Skip to content

Support for CapturingTypes #12947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1cc5cf3
Cleanups
odersky Aug 17, 2021
4183685
Support for CapturingTypes
odersky Jun 26, 2021
445eac7
Suppress Mima checking in build
odersky Jun 26, 2021
6e30a15
Add capture set constraints
odersky Aug 8, 2021
fd753da
Make <:< all-or-nothing
odersky Jul 2, 2021
32a5e14
Add element validation
odersky Jul 2, 2021
dd31f20
Integrate CheckCaptures with Rechecker
odersky Jul 2, 2021
bf5f161
Add tests and some fixes
odersky Aug 8, 2021
6ab93dd
Add iterator method to SimpleIdentitySet
odersky Aug 11, 2021
e03ef8c
Cleanups and annotations suggesting changes and removals
odersky Aug 13, 2021
e76cb7d
Initial capture checker with boxes
odersky Aug 15, 2021
a76b035
Print capturing types as in paper
odersky Aug 15, 2021
21e1ae6
Allow paper syntax to parse capturing types
odersky Aug 15, 2021
c7e5ddb
Add boxmap test from paper
odersky Aug 15, 2021
ea884bd
Fix problem in decomposeProtoFunction
odersky Aug 15, 2021
203391c
Use explicit Top bounds for boxmap example
odersky Aug 16, 2021
99dc50a
Move checkCaptures before pruneErasedDefs
odersky Aug 16, 2021
0515a86
Clean up printing of capture sets
odersky Aug 16, 2021
da82287
Give Closure trees the span of the underling function
odersky Aug 16, 2021
c89072c
Fix checkNotGlobal condition for root capture set
odersky Aug 16, 2021
636c57c
Fix tests
odersky Aug 16, 2021
1214a67
Fix noCaptures condition
odersky Aug 16, 2021
550de29
Include call captures for parameterless methods
odersky Aug 17, 2021
f3153a4
Revert "Give Closure trees the span of the underling function"
odersky Aug 17, 2021
ea313fd
Skip closure nodes when checking conformance
odersky Aug 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ jobs:
./project/scripts/sbt ";scala3-bootstrapped/compile; scala3-bootstrapped/test;sjsSandbox/run;sjsSandbox/test;sjsJUnitTests/test;sjsCompilerTests/test ;sbt-test/scripted scala2-compat/* ;configureIDE ;stdlib-bootstrapped/test:run ;stdlib-bootstrapped-tasty-tests/test; scala3-compiler-bootstrapped/scala3CompilerCoursierTest:test"
./project/scripts/bootstrapCmdTests

- name: MiMa
run: |
./project/scripts/sbt ";scala3-interfaces/mimaReportBinaryIssues ;scala3-library-bootstrapped/mimaReportBinaryIssues ;scala3-library-bootstrappedJS/mimaReportBinaryIssues"
#- name: MiMa
# run: |
# ./project/scripts/sbt ";scala3-interfaces/mimaReportBinaryIssues ;scala3-library-bootstrapped/mimaReportBinaryIssues ;scala3-library-bootstrappedJS/mimaReportBinaryIssues"

test_windows_fast:
runs-on: [self-hosted, Windows]
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dotc

import core._
import Contexts._
import typer.{TyperPhase, RefChecks}
import typer.{TyperPhase, RefChecks, CheckCaptures}
import parsing.Parser
import Phases.Phase
import transform._
Expand Down Expand Up @@ -84,6 +84,8 @@ class Compiler {
new ExplicitSelf, // Make references to non-trivial self types explicit as casts
new ElimByName, // Expand by-name parameter references
new StringInterpolatorOpt) :: // Optimizes raw and s string interpolators by rewriting them to string concatenations
List(new PreRecheck) :: // Preparations for check captures phase, enabled under -Ycc
List(new CheckCaptures) :: // Check captures, enabled under -Ycc
List(new PruneErasedDefs, // Drop erased definitions from scopes and simplify erased expressions
new UninitializedDefs, // Replaces `compiletime.uninitialized` by `_`
new InlinePatterns, // Remove placeholders of inlined patterns
Expand All @@ -101,8 +103,6 @@ class Compiler {
new TupleOptimizations, // Optimize generic operations on tuples
new LetOverApply, // Lift blocks from receivers of applications
new ArrayConstructors) :: // Intercept creation of (non-generic) arrays and intrinsify.
List(new PreRecheck) ::
List(new TestRecheck) ::
List(new Erasure) :: // Rewrite types to JVM model, erasing all type parameters, abstract types and refinements.
List(new ElimErasedValueType, // Expand erased value types to their underlying implmementation types
new PureStats, // Remove pure stats from blocks
Expand Down
8 changes: 1 addition & 7 deletions compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,10 @@ object Trees {
/** Tree's denotation can be derived from its type */
abstract class DenotingTree[-T >: Untyped](implicit @constructorOnly src: SourceFile) extends Tree[T] {
type ThisTree[-T >: Untyped] <: DenotingTree[T]
override def denot(using Context): Denotation = typeOpt match {
override def denot(using Context): Denotation = typeOpt.stripped match
case tpe: NamedType => tpe.denot
case tpe: ThisType => tpe.cls.denot
case tpe: AnnotatedType => tpe.stripAnnots match {
case tpe: NamedType => tpe.denot
case tpe: ThisType => tpe.cls.denot
case _ => NoDenotation
}
case _ => NoDenotation
}
}

/** Tree's denot/isType/isTerm properties come from a subtree
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/config/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,6 @@ object Config {
* reduces the number of allocated denotations by ~50%.
*/
inline val reuseSymDenotations = true

inline val printCaptureSetsAsPrefix = true
}
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/config/Printers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ object Printers {

val default = new Printer

val capt = noPrinter
val constr = noPrinter
val core = noPrinter
val checks = noPrinter
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ private sealed trait YSettings:
val YcheckInit: Setting[Boolean] = BooleanSetting("-Ysafe-init", "Ensure safe initialization of objects")
val YrequireTargetName: Setting[Boolean] = BooleanSetting("-Yrequire-targetName", "Warn if an operator is defined without a @targetName annotation")
val Yrecheck: Setting[Boolean] = BooleanSetting("-Yrecheck", "Run type rechecks (test only)")
val Ycc: Setting[Boolean] = BooleanSetting("-Ycc", "Check captured references")

/** Area-specific debug output */
val YexplainLowlevel: Setting[Boolean] = BooleanSetting("-Yexplain-lowlevel", "When explaining type errors, show types at a lower level.")
Expand Down
Loading