Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 07c0e16

Browse files
jchybWojciechMazur
authored andcommitted
Add more docs and examples
[Cherry-picked e611110]
1 parent 04ac74e commit 07c0e16

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

‎compiler/src/dotty/tools/dotc/inlines/Inliner.scala‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,9 @@ class Inliner(val call: tpd.Tree)(using Context):
445445

446446
/** Map back all TermRefs that match the right element in `opaqueProxies` to the
447447
* corresponding left element.
448+
* E.g. for a previously created
449+
* `val proxy1ドル = Time {type OpaqueInt = Int}` as part of the ongoing inlining
450+
* a `List[proxy1ドル.OpaqueInt]` will be mapped back into a `List[Time.OpaqueInt]`.
448451
*/
449452
protected val mapBackToOpaques = TreeTypeMap(
450453
typeMap = new TypeMap:
@@ -507,8 +510,19 @@ class Inliner(val call: tpd.Tree)(using Context):
507510

508511
def thisTypeProxyExists = !thisProxy.isEmpty
509512

510-
// Unpacks `val ObjectDef$_this: ObjectDef.type = ObjectDef` reference back into ObjectDef reference
511-
// For nested transparent inline calls, ObjectDef will be an another proxy, but that is okay
513+
/** Maps a type that includes a thisProxy (e.g. `TermRef(NoPrefix,val Foo$_this)`)
514+
* by reading the defTree belonging to that thisProxy (`val Foo$_this: Foo.type = AnotherProxy`)
515+
* back into its original reference (`AnotherProxy`, which is directly or indirectly a refinement on `Foo`)
516+
*
517+
* Usually when we end up with another proxy like this, we will be able to further unwrap it back
518+
* into `Foo` with mapBackToOpaques, but, for nested transparent inline calls, `AnotherProxy` will be
519+
* a proxy created by inlining the outer calls, that we might not be able to further unwrap this way
520+
* (as those proxies will not be a part of opaqueProxies created during this inlining).
521+
* We leave that as it is and treat this behavior as intended (see documentation with an example in
522+
* `Opaque Types in Transparent Inline Methods` section in `opaques-details.md`),
523+
* as we might need those opaques to have visible right hand sides for successful
524+
* typechecking of the outer inline call.
525+
*/
512526
val thisTypeUnpacker =
513527
TreeTypeMap(
514528
typeMap = new TypeMap:
@@ -522,6 +536,15 @@ class Inliner(val call: tpd.Tree)(using Context):
522536
}
523537
)
524538

539+
/** Returns the result type of the Inlined code block after removing thisProxy and opaqueProxy TermRefs.
540+
* E.g. for an Inlined tree returning Block of type `Option[Foo$_this.OpaqueInt]`,
541+
* and for proxies:
542+
* ```
543+
* val $proxy1: Foo.type{type OpaqueInt = Int} = = ...
544+
* val Foo$_this: ($proxy1 : Foo.type{type OpaqueInt = Int}) = ...
545+
* ```
546+
* the method will return: `Foo.OpaqueInt`
547+
*/
525548
def unpackProxiesFromResultType(inlined: Inlined): Type =
526549
if thisTypeProxyExists then mapBackToOpaques.typeMap(thisTypeUnpacker.typeMap(inlined.expansion.tpe))
527550
else inlined.tpe

‎compiler/src/dotty/tools/dotc/inlines/Inlines.scala‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,10 +579,14 @@ object Inlines:
579579
part => part.typeSymbol.is(Opaque) && owners.contains(part.typeSymbol.owner)
580580
)
581581

582-
/* Remap ThisType nodes that are incorrect in the inlined context.
583-
* Incorrect ThisType nodes can cause unwanted opaque type dealiasing later
584-
* See test i113461-d
585-
* */
582+
/** Remap ThisType nodes that are incorrect in the inlined context.
583+
* Incorrect ThisType nodes can cause unwanted opaque type dealiasing later.
584+
* E.g. if inlined in a `<root>.Foo` package (but outside of <root>.Foo.Bar object) we will map
585+
* `TermRef(ThisType(TypeRef(ThisType(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object Foo),Bar$)),MyOpaque$)),one)`
586+
* into
587+
* `TermRef(TermRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object Foo),object Bar),object MyOpaque),val one)`
588+
* See test i13461-d
589+
*/
586590
def fixThisTypeModuleClassReferences(tpe: Type): Type =
587591
val owners = ctx.owner.ownersIterator.toSet
588592
TreeTypeMap(

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /