Skip to content
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

Add the Tasty Reader [ci: last-only] #9109

Merged
merged 282 commits into from Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
282 commits
Select commit Hold shift + click to select a range
acfb44e
Support curried overloads with signatures, WIP on HK signatures
bishabosha Sep 20, 2019
a298de1
rename TASTY -> Tasty; delete unneeded code
bishabosha Sep 23, 2019
928f01b
Factor out dotc APIs to TastyUniverse
bishabosha Sep 23, 2019
9186237
delete more code
bishabosha Sep 23, 2019
5e03764
support template parents with type parameters
bishabosha Sep 23, 2019
2654a72
unpickle Functor from TASTY
bishabosha Sep 24, 2019
84b5fc4
use typeSymbolDirect
bishabosha Sep 24, 2019
524c4ba
Unpickle bounded variants of Functor
bishabosha Sep 25, 2019
de03cb7
Update README and publish tests
bishabosha Sep 25, 2019
42d2316
ignore Extension flag, suspend unpickling Monad
bishabosha Sep 26, 2019
56a782a
Avoid too precise type for TYPEREFsymbol; restore TestMonad
bishabosha Sep 26, 2019
08547f9
change TastyFlags to AnyVal
bishabosha Sep 27, 2019
48d66cf
TestReader blocked by dotc
bishabosha Sep 27, 2019
cc5dba1
unpickle companions in same tasty file; suspend TestPair; replace Emp…
bishabosha Sep 27, 2019
7d8b352
WIP: Inner classes
bishabosha Sep 27, 2019
b574440
unpickle inner traits and objects; restore TestInner
bishabosha Sep 30, 2019
3d83813
unpickle traits with abstract type members
bishabosha Sep 30, 2019
17d72f8
support inheritance of object member
bishabosha Oct 1, 2019
c29512b
unify handling of hk params on methods and parents
bishabosha Oct 2, 2019
ed7c88c
unpickle value class with private ctor
bishabosha Oct 3, 2019
f71c446
create suspended TestEnum
bishabosha Oct 4, 2019
de0dcbc
Restore TestEnum, do not unpickle typeParams for constructors
bishabosha Oct 4, 2019
7b26c04
Add simple regression test runner for tasty files
bishabosha Oct 7, 2019
06e21b3
cleanup TastyTest
bishabosha Oct 8, 2019
43080ca
test lazy val
bishabosha Oct 8, 2019
340b0e5
Restore TestPair, initial support for module TYPEREFs
bishabosha Oct 8, 2019
7a9c84a
create suspended TestExtensions
bishabosha Oct 8, 2019
a9233e9
Document TastyTest framework
bishabosha Oct 11, 2019
2b12fac
create suspended TestJColour for j.l.Enum
bishabosha Oct 14, 2019
fcb3287
remove dependency on dotc and coursier on the path
bishabosha Oct 14, 2019
8de25f2
add -help to TastyTest, invoke scala compiler directly, add args for …
bishabosha Oct 16, 2019
a050c50
remove early initialiser in ScalacUnpickler
bishabosha Oct 16, 2019
209fd29
cleanup TastyTest
bishabosha Oct 16, 2019
c1b88e4
make reframe TastyTest as a runner with multiple suite kinds
bishabosha Oct 22, 2019
d4e810f
Support neg tests in TastyTest and add an example neg test
bishabosha Oct 23, 2019
a82af45
accumulate errors in TastyTest suites
bishabosha Oct 24, 2019
592b0fe
rework whitelisting sources
bishabosha Oct 28, 2019
ec03c8b
refactor Runner
bishabosha Oct 28, 2019
9bbfb6b
Correctly capture thrown errors in run tests, experiment with test su…
bishabosha Oct 28, 2019
5e7177e
collective errors on Suite
bishabosha Oct 29, 2019
e0d0477
sync with standalone tastytest version
bishabosha Oct 30, 2019
c43dbd2
invoke dotc in same jvm process
bishabosha Oct 30, 2019
e7d868b
Protect against thrown errors in scalac and dotc; migrate all tests t…
bishabosha Oct 31, 2019
7d2a027
Add positive super call test; suspend symbollic operator test
bishabosha Oct 31, 2019
adda23f
update tests and README for dotty 0.20.0-RC1
bishabosha Nov 3, 2019
aca29fe
make sbt projects for tastytest, use new diff tool
bishabosha Nov 5, 2019
c11d329
add tasty/test to testAll; disable other tests
bishabosha Nov 5, 2019
ad2a187
Split up tastytest
bishabosha Nov 8, 2019
7856c2d
Update docs and remove pre from neg tests
bishabosha Nov 11, 2019
fc1c789
implement PARAMEND
bishabosha Nov 6, 2019
f48b925
implement open modifier
bishabosha Nov 7, 2019
5830243
correct PARAMS tag value
bishabosha Nov 8, 2019
8b29c90
depend on dotty with tasty version 18
bishabosha Nov 8, 2019
f17a577
add test output
bishabosha Nov 22, 2019
4e0628b
Add Name ADT to scala.tools.nsc.tasty
bishabosha Nov 22, 2019
8e84173
Reify Tasty Names, which allows to reduce coupling
bishabosha Nov 26, 2019
8cce0a4
reduce dependencies on symbolTable
bishabosha Nov 27, 2019
60449a8
make TastyUniverse a parameter not a parent
bishabosha Nov 27, 2019
71d23f0
unpickle is now extension method
bishabosha Nov 28, 2019
2a7543c
default canonical LambdaType now PolyType, add pos suites
bishabosha Nov 29, 2019
22731fd
replace def forwarders to objects with forwarders to factory method
bishabosha Nov 29, 2019
c5daaec
downgrade to dotty 0.20.0-RC1
bishabosha Dec 3, 2019
b43698f
support SHAREDterm, add neg-false test
bishabosha Dec 3, 2019
093b21a
move enum flag to TastyFlags. neg-false test for scala2 style enum pa…
bishabosha Dec 3, 2019
55f9460
add different SColour test for run
bishabosha Dec 3, 2019
48dc766
fix diff tools, prepare IO test
bishabosha Dec 3, 2019
79b1256
unpickle byname type param, move TestIO to pos
bishabosha Dec 3, 2019
7b23416
ensure bynametype has function type. Allow to skip check on neg test
bishabosha Dec 5, 2019
7898de2
better logging output
bishabosha Dec 5, 2019
232230f
minimise type intersections issue. Identify dotty intersecion or unio…
bishabosha Dec 5, 2019
5a83b3c
Resolve intersection types
bishabosha Dec 6, 2019
049d324
add Implicit flag not Given
bishabosha Dec 9, 2019
9c1a888
Add nameTagToString to TastyFormat
bishabosha Dec 9, 2019
8f2ad2f
unpickle inlineaccessor and superaccessor names
bishabosha Dec 9, 2019
6b2face
improve error messages
bishabosha Dec 9, 2019
bb093f3
adjust scala 3 flags show output
bishabosha Dec 9, 2019
89c4f0f
unpickle intersection types in type position
bishabosha Dec 9, 2019
63acd0d
dotty macros now have their own flag, stub factor10 intent library fo…
bishabosha Dec 9, 2019
5fb8dc9
update TODO, add test for trait initialisers
bishabosha Dec 16, 2019
ffcda89
add support for unpickling unescaped operator names; unsuspend TestPr…
bishabosha Dec 17, 2019
355c48f
can unpickle some backticked names, will have to wait until dotty 0.2…
bishabosha Dec 18, 2019
f224d84
more precise Intersection test. Assert that default arguments are unr…
bishabosha Dec 18, 2019
74cbfd4
unpickle overloaded methods
bishabosha Dec 19, 2019
0a9a083
unpickle default parameters
bishabosha Dec 19, 2019
c83ec32
Special case more names
bishabosha Dec 20, 2019
5d8a0c9
Add regression test for empty package
bishabosha Dec 20, 2019
9736f73
add to scolour test
bishabosha Dec 20, 2019
23427b8
Unpickle extension methods
bishabosha Dec 20, 2019
efa2cfa
extract extension method symbol and type factorys
bishabosha Jan 6, 2020
5fb42e0
move extension method symbol generation
bishabosha Jan 6, 2020
7ca32d8
WIP
bishabosha Jan 8, 2020
a7e951e
add pos-false test, resolve reachability issue, must solve exhaustion…
bishabosha Jan 8, 2020
ee5fdbd
Tasty signatures now support array types
bishabosha Jan 9, 2020
15ced1c
Read vararg trees
bishabosha Jan 10, 2020
f6bc167
unpickle annotations, special case scala.annotation.internal.Child fo…
bishabosha Jan 14, 2020
6a7eb2e
signatures now look for module in mirror, restore ModuleInCtor
bishabosha Jan 14, 2020
4bd6f3e
unpickle singleton types correctly in arguments
bishabosha Jan 14, 2020
dae1d82
refactor typeref logic
bishabosha Jan 15, 2020
64329ca
refactor annotation logic
bishabosha Jan 15, 2020
dcba58d
Unpickle If (tested with an annotation)
bishabosha Jan 15, 2020
aa2d802
support NamedArg tree unpickle, begin support for match
bishabosha Jan 15, 2020
ecdac2f
avoid caching a LambdaType, put more complex expressions in parents
bishabosha Jan 17, 2020
f7a71eb
resolve arbitrary tree in ctor problem
bishabosha Jan 23, 2020
f21d101
Modify test functor; ensure folders are published
bishabosha Jan 27, 2020
14cd342
fix #25 - Handle a signed name in a TERMREF
bishabosha Jan 27, 2020
f621f95
remove todo document, direct users to issues
bishabosha Jan 27, 2020
2ade08b
fix breakages after rebase
bishabosha Jan 28, 2020
5d04d44
fix #24: use custom nsc reporter in neg tests
bishabosha Jan 28, 2020
afa94d5
fix #27: Add tasty-ci
bishabosha Jan 28, 2020
8261014
use merge commit instead
bishabosha Jan 28, 2020
a2cfc17
update README
bishabosha Jan 28, 2020
4057be1
try removing the push event
bishabosha Jan 28, 2020
d62b724
update README
bishabosha Jan 28, 2020
1c4ec61
flush reporter in TastyTest
bishabosha Jan 31, 2020
b823767
identify crash with test
bishabosha Jan 29, 2020
44ace0b
temporarily store a module symbol to ensure its symbol survives, allo…
bishabosha Jan 31, 2020
5209fa8
Add `@compileTimeOnly` annotation to unpickled inline def definitions
julienrf Feb 18, 2020
9284d63
Drop package prefix from a class
errikos Feb 18, 2020
14a57a9
Add .keep file to neg-false/src-2
errikos Feb 18, 2020
b25f8c7
Add HKNest test to test higher kinded types
errikos Feb 3, 2020
b6baea7
constructor returns type of owner
bishabosha Feb 3, 2020
10619ee
test consuming (* -> *) -> * from TASTy
bishabosha Feb 3, 2020
02f168e
inherit typeParams from bounds of hk lambda types; add many more tests
bishabosha Feb 4, 2020
882ec81
refactor to new mkTypeRef factory; test HK nest with covariant bounds
bishabosha Feb 4, 2020
15b52b7
simplify lambdatype canonical repr, handle contravariance
bishabosha Feb 13, 2020
530fec2
normalise typebounds in hktypeparams, handle wildcard bounds, pretty …
bishabosha Feb 14, 2020
b47989a
cleanup
bishabosha Feb 14, 2020
ecbabf9
add more test
bishabosha Feb 14, 2020
12b418e
Add test that causes error when compiled with dotty
bishabosha Feb 17, 2020
024e635
WIP, investigate bounds stripping for lower bounds with polytype
bishabosha Feb 17, 2020
5e5794a
normalise typebounds in hk types
bishabosha Feb 17, 2020
9c7ac7e
refactor
bishabosha Feb 18, 2020
2a6297a
merge parameters of type lambdas in bounds
bishabosha Feb 18, 2020
9220891
error on curried type lambda
bishabosha Feb 18, 2020
05de5e3
refactor
bishabosha Feb 18, 2020
dd4f8d8
refactor
bishabosha Feb 19, 2020
517dd9d
survive more pathological cases of type lambdas in bounds
bishabosha Feb 19, 2020
515d382
improve error reporting
bishabosha Feb 19, 2020
7942c2e
refactor LambdaEncoding
bishabosha Feb 20, 2020
8528afa
refactor lambdaTypeCompanion
bishabosha Feb 21, 2020
128aeae
refine symbol table settings type in TastyKernel
bishabosha Feb 24, 2020
65e39a5
add test to show flag disables annotations
bishabosha Feb 24, 2020
8d88549
upgrade to TASTy version 18, refactor flags
bishabosha Feb 24, 2020
642e28d
add tasty/dotc and tasty/scalac tasks for ease of use
bishabosha Feb 25, 2020
14b6a74
add more sbt tasks: code runner and dotty decompiler
bishabosha Feb 27, 2020
84b2746
change to Dotty 0.21.0, update readme, simplify test runner
bishabosha Feb 27, 2020
44a1f21
refactor
bishabosha Feb 28, 2020
a1e3aca
Upgrade tasty version 19, drop variant names and adjust bounds
bishabosha Feb 28, 2020
7c8b8cd
clone LambdaPolyType with new variances
bishabosha Mar 1, 2020
193fda1
revert to in place update of variance flags
bishabosha Mar 1, 2020
54658fa
support dotty enum constants
bishabosha Mar 2, 2020
00b05e0
Ensure paths are preserved for type member selection
bishabosha Mar 11, 2020
a8cc2b6
Add test case for refined types
bishabosha Mar 11, 2020
b7e8886
Add passing REFINEDtype run and neg tests
bishabosha Mar 12, 2020
3aea333
successful tests for REFINEDtpt including compound types
bishabosha Mar 12, 2020
21cc62d
add path dependent type test on dotty enum constant
bishabosha Mar 12, 2020
db9f3bd
support val and nullary def in REFINEDtype
bishabosha Mar 12, 2020
e59ca8f
Test methodic refinements for REFINEDtpt
bishabosha Mar 12, 2020
c2dbd56
support repeated method parameters
bishabosha Mar 20, 2020
91e23b2
unpickle SUPER and SUPERtype symbols
bishabosha Mar 23, 2020
2cbe56b
Support refinements for method, poly and values, support structural r…
bishabosha Mar 17, 2020
c01a43c
Update to use repeated parameters
bishabosha Mar 20, 2020
9d087a1
Support Implicit and Given flags on method refinements
bishabosha Mar 24, 2020
6de9ec3
add more idiomatic structural refinements
bishabosha Mar 24, 2020
4b5ffc7
Fix `tasty/test` on Windows.
sjrd Mar 24, 2020
bc86c25
add test cases
bishabosha Mar 24, 2020
15aa453
Add nested RECtype test case
bishabosha Mar 24, 2020
5897395
Tests pass for non-nested RECtype
bishabosha Mar 25, 2020
525c309
support forward-referencing RECthis and type alias refinements
bishabosha Mar 27, 2020
af0d777
Add test for path dependent val refinement
bishabosha Mar 30, 2020
4d9e2ad
add test cases for TERMREFin/TYPEREFin
bishabosha Mar 30, 2020
2aae82f
Support TERMREFin and TYPEREFin, look for type members in type ctor
bishabosha Mar 30, 2020
45f07e5
Support Dotty 0.23.0-RC1; opaque type aliases are transparent
bishabosha Mar 31, 2020
117d5cf
re-enable tests
bishabosha Apr 1, 2020
f496ac9
add new github action to run on push to tasty_reader
bishabosha Apr 1, 2020
c32056f
Cleanup warnings
bishabosha Apr 1, 2020
78c9b63
delete dead code and comments, refactor
bishabosha Apr 1, 2020
d4519fe
refactor reading a member by name, enabling dotty java enums
bishabosha Apr 2, 2020
a070f31
This is a very disruptive change, affecting bytecode gen (could be av…
bishabosha Apr 2, 2020
82f4d40
Fail fast when select name from type is no symbol
bishabosha Apr 2, 2020
92bbfc5
Add TastyMode, test when parent is missing from classpath
bishabosha Apr 2, 2020
daa0620
Add test when type in a method is missing from classpath
bishabosha Apr 2, 2020
a39b9c4
Add test when annotation on top-level class is missing from classpath
bishabosha Apr 2, 2020
d9007f4
refactor tasty name, add ErasedTypeRef, special case repeated class
bishabosha Apr 3, 2020
60f9d23
unify error handling and logging
bishabosha Apr 3, 2020
4cd343b
remove module symbol cache from context
bishabosha Apr 3, 2020
147a712
unify attachTypeError with unsupportedError
bishabosha Apr 3, 2020
2b2cceb
refactor, error handling in two steps now
bishabosha Apr 4, 2020
2ea8fff
err on union in class tparam position
bishabosha Apr 4, 2020
fa413ec
test when ErasedTypeRef is missing from class path
bishabosha Apr 4, 2020
481b580
make assertions about metaprogramming features
bishabosha Apr 4, 2020
743dc26
match types and erased refinements are unsupported
bishabosha Apr 4, 2020
d0be213
remove comment
bishabosha Apr 4, 2020
62e0d4c
avoid resolving ctor of parent
bishabosha Apr 6, 2020
443ec2b
Add mode to track when in an annotation and adjust error message to suit
bishabosha Apr 6, 2020
152ca2c
refactor error handling, test unsupported trees in annotations
bishabosha Apr 6, 2020
076a6fa
Merge readParentFromTerm with readTerm
bishabosha Apr 6, 2020
78dd6d9
refactor
bishabosha Apr 7, 2020
d02d42e
only expose TastyName to TreeUnpickler
bishabosha Apr 7, 2020
9979e45
require TypeName rather than pass boolean flag
bishabosha Apr 7, 2020
944c36c
reduce dependencies
bishabosha Apr 7, 2020
6544fd6
delete more code
bishabosha Apr 7, 2020
4c12969
Test open class, dependent methods, trait params
bishabosha Apr 8, 2020
25c1514
remove CI from PR
bishabosha Apr 8, 2020
2119b2e
Delete SourceFile.scala
bishabosha Apr 8, 2020
2915488
support export flag
bishabosha Apr 8, 2020
c9d3ee9
add headers
bishabosha Apr 8, 2020
ec1204a
ensure symbollic classes can be read from erasedtyperef
bishabosha Apr 9, 2020
97bb801
Simplify refined/rec types
bishabosha Apr 14, 2020
5ab29c3
refactor annotations
bishabosha Apr 15, 2020
52cdfb3
refactor TastyFlags
bishabosha Apr 17, 2020
652fdfb
move TastyFlags. Remove Scope dependency
bishabosha Apr 17, 2020
a74965d
remove TypeBounds dependency
bishabosha Apr 17, 2020
c0bfb3b
better semantics for symbol.not(flags)
bishabosha Apr 17, 2020
42d0039
better logging
bishabosha Apr 18, 2020
32d114f
Update src/library/scala/collection/mutable/StringBuilder.scala
bishabosha Apr 20, 2020
d616154
scan trees does not complete symbols
bishabosha Apr 21, 2020
00480ba
annotations use lazy val to compute tree
bishabosha Apr 21, 2020
1c9e9ec
can visit either module or module class first
bishabosha Apr 22, 2020
20cb1a7
add CI conditionally
bishabosha Jun 10, 2020
5b3118f
no more ui.
lrytz Jun 9, 2020
ab4916a
intellij
lrytz Jun 9, 2020
b6fa7d4
fix tasty/test
lrytz Jun 11, 2020
b5a966b
use commonSettings in tasty subproject
bishabosha Jun 11, 2020
b08e9e9
enum values are now case objects
bishabosha Jun 18, 2020
f55cd66
fix bytecode for dotty enum singletons, remove DottyEnumTag constant
bishabosha Jun 19, 2020
8ee1cb1
refactor erasure for singletons, test more of their behaviour
bishabosha Jun 22, 2020
f081d54
be more precise with flags from tasty
bishabosha Jun 23, 2020
be32ab4
Remove symbol creation for BIND tags
bishabosha Jun 23, 2020
9409a32
remove ScalacUnpickler, TreeSectionUnpickler and SectionUnpickler
bishabosha Jun 23, 2020
d9b8e94
add documentation
bishabosha Jun 23, 2020
bb8594b
add patmat test
bishabosha Jun 24, 2020
d6cca66
create a single scripted runner for local tasty testing
bishabosha Jun 24, 2020
2668149
add AnyVal erasure of enums test
bishabosha Jun 24, 2020
113e70f
rework documentation
bishabosha Jun 24, 2020
50cf0fc
update documentation
bishabosha Jun 25, 2020
a9b52fe
eliminate Ident and Annotation from TastyCore
bishabosha Jun 25, 2020
1fc48cc
insert parens to nillary applications
bishabosha Jun 26, 2020
1835f94
add more refinement tests
bishabosha Jun 30, 2020
ae1b4f6
TASTY is classfile attribute
bishabosha Jul 2, 2020
85a574e
Force annotations in TreeUnpickler and not Pattern Matching
bishabosha Jul 2, 2020
94f693f
Delay forcing annotations in template body until parents are added to…
bishabosha Jul 7, 2020
f8c2212
Find overloads by converting types to ErasedTypeRef.
bishabosha Jul 7, 2020
0721788
Merge pull request #106 from scalacenter/tasty/pick-erased-type-ref
bishabosha Jul 7, 2020
0104ffe
Fix JavaUniverseForce
lrytz Jul 8, 2020
bb9f327
Merge pull request #107 from lrytz/pr8865
bishabosha Jul 8, 2020
4c4da06
remove usage of extension methods in scala 3 sources
bishabosha Jul 14, 2020
c34afec
remove github actions
bishabosha Jul 14, 2020
31d68ed
don't publish tastytest
lrytz Jul 15, 2020
61049d2
Merge pull request #109 from lrytz/pr9109
bishabosha Jul 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 29 additions & 1 deletion build.sbt
Expand Up @@ -891,6 +891,16 @@ lazy val partest = configureAsSubproject(project)
)
)

lazy val tastytest = configureAsSubproject(project)
.dependsOn(library, reflect, compiler)
.settings(disableDocs)
.settings(publish / skip := true)
.settings(
name := "scala-tastytest",
description := "Scala TASTy Integration Testing Tool",
libraryDependencies ++= List(diffUtilsDep, TastySupport.dottyCompiler),
)

// An instrumented version of BoxesRunTime and ScalaRunTime for partest's "specialized" test category
lazy val specLib = project.in(file("test") / "instrumented")
.dependsOn(library, reflect, compiler)
Expand Down Expand Up @@ -979,6 +989,22 @@ lazy val junit = project.in(file("test") / "junit")
Test / unmanagedSourceDirectories := List(baseDirectory.value)
)

lazy val tasty = project.in(file("test") / "tasty")
.settings(commonSettings)
.dependsOn(tastytest)
.settings(disableDocs)
.settings(publish / skip := true)
.settings(
Test / fork := true,
libraryDependencies += junitInterfaceDep,
testOptions += Tests.Argument(TestFrameworks.JUnit, "-a", "-v"),
testOptions in Test += Tests.Argument(
s"-Dtastytest.src=${baseDirectory.value}",
s"-Dtastytest.packageName=tastytest"
),
Compile / unmanagedSourceDirectories := Nil,
Test / unmanagedSourceDirectories := List(baseDirectory.value/"test"),
)

lazy val scalacheck = project.in(file("test") / "scalacheck")
.dependsOn(library, reflect, compiler, scaladoc)
Expand Down Expand Up @@ -1237,6 +1263,7 @@ lazy val root: Project = (project in file("."))
partestDesc("--srcpath scaladoc"),
partestDesc("--srcpath macro-annot"),
partestDesc("--srcpath async"),
(tasty / Test / Keys.test).result map (_ -> "tasty/test"),
(osgiTestFelix / Test / Keys.test).result map (_ -> "osgiTestFelix/test"),
(osgiTestEclipse / Test / Keys.test).result map (_ -> "osgiTestEclipse/test"),
(library / mimaReportBinaryIssues).result map (_ -> "library/mimaReportBinaryIssues"),
Expand Down Expand Up @@ -1482,7 +1509,6 @@ intellij := {
moduleDeps(junit).value,
moduleDeps(library).value,
moduleDeps(manual).value,
moduleDeps(testkit).value,
moduleDeps(partest).value,
moduleDeps(partestJavaAgent).value,
moduleDeps(reflect).value,
Expand All @@ -1491,7 +1517,9 @@ intellij := {
moduleDeps(scalacheck, config = Test).value.copy(_1 = "scalacheck-test"),
moduleDeps(scaladoc).value,
moduleDeps(scalap).value,
moduleDeps(tastytest).value,
moduleDeps(testP).value,
moduleDeps(testkit).value,
)
}

Expand Down
189 changes: 189 additions & 0 deletions doc/internal/tastyreader.md
@@ -0,0 +1,189 @@
# TASTy Reader For Scala 2

The [**TASTy Reader For Scala 2**](https://scala.epfl.ch/projects.html#tastyScala2), included in the Scala 2.x Compiler will enable usage in Scala `2.13.x` of dependencies that have been compiled with `dotc`, the reference compiler of Scala `3.0`.

TASTy is an intermediate representation of a Scala program after type checking and term elaboration, such as inference of implicit parameters. When compiling code with Scala 3, a single TASTy document is associated with each pair of root class and companion object. Within a TASTy document, the public API of those roots and any inner classes can be read, in a similar way to pickles in the Scala 2.x series.

## Working with the code

### Compiler flags

- `-Ydebug-tasty` enables rich output when traversing tasty files, important for tracing the history of events when diagnosing errors.

- `-Ytasty-no-annotations` ignores all annotations on tasty symbols, may be useful for ignoring complex annotations that are unsupported, but will prevent safety checks for pattern matching.

### Entry Points

A classfile is assumed to have an associated TASTy file if it has a `TASTY` classfile attribute (not available through
Java reflection). This attribute contains a UUID that matches a UUID in the header of a sibling `.tasty` file of the
same directory as the classfile. This file is then found and the UUIDs are compared in
`scala.tools.nsc.symtab.classfile.ClassfileParser`.
After validation of the header, the tasty file is traversed in `scala.tools.nsc.tasty.TastyUnpickler.unpickle`, which
reads any definitions into the symbol table of the compiler.

### Concepts in TASTy

A TASTy document is composed of a header, which contains a magic number `0x5CA1AB1F`, a version number and a UUID.
The TASTy document then is composed of a list of names, followed by customisable "sections". The section we are
interested in for Scala 2 is the "ASTs" section. The ASTs section contains a package definition for the root class and
companion of the tasty file. In TASTy, both terms and types are made of trees, and sometimes trees can be reused in
either term or type position, for example path selections. There are five main concepts in TASTy:
- Name: has many roles
- An identifier associated with a Symbol,
- A cursor to lookup terms or types within the scope of a parent type, including resolving a specific overload,
or distinguishing between a class and its companion object's implementation class.
- To describe the erased signature of an method.
- Flags: an enumerated set of properties for a Symbol, e.g. if it is a Method, Object, Param, etc.
- Symbol: an aggregate of Flags, a Name and a Type, representing the semantic information about a definition
- Type: corresponds to a scala reflect Type, can be lazy
- Term: corresponds to a scala reflect Tree and has a Type. Annotations are represented as Terms

### Workflow

A typical workflow for experimenting with the TASTy reader is to:
1) create a workspace directory `$issue`, e.g. `sandbox/issue`
2) create an output directory `$out`, e.g. `$issue/bin`
3) create a Scala 3 source file `$src3`, e.g. `$issue/FancyColours.scala`
4) compile the Scala 3 source file to `$out`:
- `dotc -d $out $src3`
5) create a Scala 2 source file, `$src2`, that uses some symbols from `$src3`, e.g. `$issue/TestFancyColours.scala`
6) compile the Scala 2 source file, adding any symbols from `$src3` to the classpath:
- `scalac -Ydebug-tasty -d $out -classpath $out $src2`

Here are some example source files from the above scenario:
```scala
// FancyColours.scala - compile with Scala 3

trait Pretty:
self: Colour =>

trait Dull:
self: Colour =>

enum Colour:
case Pink extends Colour with Pretty
case Red extends Colour with Dull
```
```scala
// TestFancyColours.scala - compile with Scala 2

object TestFancyColours {

def describe(c: Colour) = c match {
case Colour.Pink => "Amazing!"
case Colour.Red => "Yawn..."
}

def describePretty(c: Pretty) = c match {
case Colour.Pink => "Amazing!"
}

def describeDull(c: Dull) = c match {
case Colour.Red => "Yawn..."
}

}
```

The [Script Runner](#script-runner) section describes some commands that support this workflow and can be run from sbt; which also handles providing the supported version of `dotc` on the classpath.

Below is an example of using the [Script Runner](#script-runner) to simplify iterative development of the scenario above:

1) First, compile the Scala 3 code with `tasty/test:runMain scala.tools.tastytest.Scripted dotc $out $issue/FancyColours.scala`.
2) Next, compile the test code from Scala 2 with `tasty/test:runMain scala.tools.tastytest.Scripted scalac $out $issue/TestFancyColours.scala -Ydebug-tasty`, which will also put the contents of `$out` on the classpath.
3) To aid with debugging, inspect the TASTy structure for `Colour` with `tasty/test:runMain scala.tools.tastytest.Scripted dotcd $out/Colour.tasty -print-tasty`

In the above, relative paths will be calculated from the working directory of `tasty/test`.

Because these commands are run from sbt, incremental changes can be made to the code for the TASTy reader and then step `2` can be immediately re-run to observe new behaviour of the compiler.

In the output of the above step `2`, you will see the the following snippet, showing progress in traversing TASTy and understanding the definition of `trait Dull`:
```scala
#[trait Dull]: Addr(4) completing Symbol(trait Dull, #6286):
#[trait Dull]: Addr(7) No symbol found at current address, ensuring one exists:
#[trait Dull]: Addr(7) registered Symbol(value <local Dull>, #7240) in trait Dull
#[trait Dull]: Addr(9) Template: reading parameters of trait Dull:
#[trait Dull]: Addr(9) Template: indexing members of trait Dull:
#[trait Dull]: Addr(22) No symbol found at current address, ensuring one exists:
#[trait Dull]: Addr(22) ::: => create DEFDEF <init>
#[trait Dull]: Addr(22) parsed flags Stable | Method
#[trait Dull]: Addr(22) registered Symbol(constructor Dull, #7241) in trait Dull
#[trait Dull]: Addr(9) Template: adding parents of trait Dull:
#[trait Dull]: Addr(9) reading type TYPEREF:
#[trait Dull]: Addr(11) reading type TERMREFpkg:
#[trait Dull]: Addr(13) Template: adding self-type of trait Dull:
#[trait Dull]: Addr(15) reading term IDENTtpt:
#[trait Dull]: Addr(17) reading type TYPEREF:
#[trait Dull]: Addr(19) reading type THIS:
#[trait Dull]: Addr(20) reading type TYPEREFpkg:
#[trait Dull]: Addr(22) Template: self-type is Colour
#[trait Dull]: Addr(22) Template: Updated info of trait Dull extends AnyRef
#[trait Dull]: Addr(4) typeOf(Symbol(trait Dull, #6286)) =:= Dull; owned by package <empty>
```

### Tagged comments
Comments beginning with `TODO [tasty]:` express concerns specific to the implementation of the TASTy reader. These should be considered carefully because of either the disruptive changes they make to the rest of the code base, or as a note that there may be a more correct solution, or as a placeholder to outline missing features of Scala 3 that are not yet backported to Scala 2.x.

## Testing

The framework for testing the TASTy reader is contained in the `tastytest` subproject.

The `tasty` project is an example subproject depending on `tastytest`, used to test the functionality of the TASTy
reader. Test sources are placed in the `test/tasty` directory of this repository and tested with the sbt task
`tasty/test`. Several suites exist that build upon primitives in `tastytest`:
- `run`: test that classes can depend on Scala 3 classes and execute without runtime errors.
- `neg`: assert that scala 2 test sources depending on Scala 3 classes do not compile
- `neg-isolated`: assert that code depending on symbols not on the classpath fails correctly.
- `pos`: The same as `run` except with no runtime checking, useful for validating types while waiting for bytecode to align.
- `pos-false-noannotations`: the same as `pos` but asserting code falsely compiles without warnings or errors when annotations are ignored.

### Script Runner

A key tool for working with the tasty reader on individual test cases is `scala.tools.tastytest.Scripted`. It provides several sub commands which share a common implementation with the core of `tastytest`, meaning that the behaviour is identical.
Each sub command is executed with the Dotty standard library and tooling on the classpath, with the version determined by
`TastySupport.dottyCompiler` in the build definition. All relative paths will use the working directory `tasty/test`:

In the sbt shell the `Scripted` runner can be executed by `tasty/test:runMain scala.tools.tastytest.Scripted`, and provides several sub-commands:
- `dotc <out: Directory> <src: File>`: compile a Scala 3 source file, which may depend on classes already compiled in `out`.
- `dotcd <tasty: File> <args: String*>`: decompile a tasty file, pass `-print-tasty` to see the structure of the ASTs.
- `scalac <out: Directory> <src: File> <args: String*>`: compile a Scala 2 source file, which may depend on classes already compiled in `out`, including those compiled by Scala 3. `args` can be used to pass additional scalac flags, such as `-Ydebug-tasty`
- `runDotty <classpath: Paths> <classname: String>`: execute the static main method of the given class, and providing no arguments.

### tastytest Runner

`tastytest` is a testing library for validating that Scala 2 code can correctly depend on classes compiled with `dotc`, the Scala 3 compiler, which outputs TASTy trees. The framework has several suites for testing different scenarios. In each suite kind, the Scala 3 standard library is available to all test sources. `tastytest` does not implement the TestInterface so it is recommended to call its entry points from JUnit, like in `test/tasty/test/scala/tools/tastytest/TastyTestJUnit.scala`.

#### run Suites
A `run` suite tests the runtime behaviour of Scala 2 code that may extend or call into code compiled with `dotc`, and is specified as follows:

1) A root source `$src` is declared, e.g. `"run"`
2) Compile sources in `$src/pre/**/` with the Scala 2 compiler, this step may be used to create helper methods available to Scala 2 and 3 sources, or embedded test runners.
3) Compile sources in `$src/src-3/**/` with the Dotty compiler. Classes compiled in `(2)` are now on the classpath.
4) Compile sources in `$src/src-2/**/` with the Scala 2 compiler. Classes compiled in `(2)` and `(3)` are now on the classpath.
5) All compiled classes are filtered for those with file names that match the regex `(.*Test)\.class`, and have a corresponding source file in `$src/src-2/**/` matching `$1.scala`, where `$1` is the substituted name of the class file. The remaining classes are executed sequentially as tests:
- A test class must have a static method named `main` and with descriptor `([Ljava.lang.String;)V`.
- The `out` and `err` print streams of `scala.Console` are intercepted before executing the `main` method.
- A successful test must not output to either stream and not throw any runtime exceptions that are not caught within `main`.

#### pos Suites
A `pos` suite tests the compilation of Scala 2 code that may extend or call into code compiled with `dotc`, and is specified the same as `run`, except that step `(5)` is skipped. If step `(4)` succeeds then the suite succeeds.

#### neg Suites
A `neg` suite asserts which Scala 2 code is not compatible with code compiled with `dotc`, and is specified as follows:
1) A root source `$src` is declared, e.g. `"neg"`
2) Compile sources in `$src/src-3/**/` with the Dotty compiler.
3) Source files in `$src/src-2/**/` are filtered for those with names that match the regex `(.*)_fail.scala`, and an optional check file that matches `$1.check` where `$1` is the substituted test name, and the check file is in the same directory. These are sources expected to fail compilation.
4) Compile scala sources in `$src/src-2/**/` with the Scala 2 compiler.
- Classes compiled in `(2)` are now on the classpath.
- If a Scala source fails compilation, check that it is in the set of expected fail cases, and that there is a corresponding check file that matches the compiler output, else collect in the list of failures.
- If an expected fail case compiles successfully, collect it in the list of failures.

#### neg-isolated Suites
A `neg-isolated` suite tests the effect of missing transitive dependencies on the classpath that are available to Scala 3 dependencies of Scala 2 sources, but not to those downstream Scala 2 sources, and is specified as follows:
1) A root source `$src` is declared, e.g. `"neg-isolated"`
2) Compile sources in `$src/src-3-A/**/` with the Dotty compiler.
3) Compile sources in `$src/src-3-B/**/` with the Dotty compiler. Classes compiled in `(2)` are now on the classpath.
3) Identical to `neg` step `(3)`
4) Compile scala sources in `$src/src-2/**/` with the Scala 2 compiler. Test validation behaviour matches `neg` step `(4)`, except for the following caveats:
- Only classes compiled in `(3)` will be on the classpath. Classes compiled in `(2)` are deliberately hidden.
- References to symbols compiled in `(3)` that reference symbols in compiled in `(2)` should trigger missing symbol errors due to the missing transitive dependency.
8 changes: 8 additions & 0 deletions project/DottySupport.scala
Expand Up @@ -8,6 +8,14 @@ import sbt.librarymanagement.{
ivy, DependencyResolution, ScalaModuleInfo, UpdateConfiguration, UnresolvedWarningConfiguration
}

/**
* Settings to support validation of TastyUnpickler against the release of dotty with the matching TASTy version
*/
object TastySupport {
val supportedTASTyRelease = "0.23.0-RC1" // TASTy version 20
val dottyCompiler = "ch.epfl.lamp" % "dotty-compiler_0.23" % supportedTASTyRelease
}

/** Settings needed to compile with Dotty,
* Only active when sbt is started with `sbt -Dscala.build.compileWithDotty=true`
* This is currently only used to check that the standard library compiles with
Expand Down
50 changes: 30 additions & 20 deletions src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala
Expand Up @@ -432,35 +432,36 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
* Otherwise it's safe to call from multiple threads.
*/
def genConstant(const: Constant): Unit = {

(const.tag: @switch) match {

case BooleanTag => bc.boolconst(const.booleanValue)
case BooleanTag => bc.boolconst(const.booleanValue)

case ByteTag => bc.iconst(const.byteValue)
case ShortTag => bc.iconst(const.shortValue)
case CharTag => bc.iconst(const.charValue)
case IntTag => bc.iconst(const.intValue)
case ByteTag => bc.iconst(const.byteValue)
case ShortTag => bc.iconst(const.shortValue)
case CharTag => bc.iconst(const.charValue)
case IntTag => bc.iconst(const.intValue)

case LongTag => bc.lconst(const.longValue)
case FloatTag => bc.fconst(const.floatValue)
case DoubleTag => bc.dconst(const.doubleValue)
case LongTag => bc.lconst(const.longValue)
case FloatTag => bc.fconst(const.floatValue)
case DoubleTag => bc.dconst(const.doubleValue)

case UnitTag => ()
case UnitTag => ()

case StringTag =>
case StringTag =>
assert(const.value != null, const) // TODO this invariant isn't documented in `case class Constant`
mnode.visitLdcInsn(const.stringValue) // `stringValue` special-cases null, but not for a const with StringTag

case NullTag => emit(asm.Opcodes.ACONST_NULL)
case NullTag => emit(asm.Opcodes.ACONST_NULL)

case ClazzTag =>
case ClazzTag =>
val tp = typeToBType(const.typeValue)
// classOf[Int] is transformed to Integer.TYPE by CleanUp
assert(!tp.isPrimitive, s"expected class type in classOf[T], found primitive type $tp")
mnode.visitLdcInsn(tp.toASMType)

case EnumTag =>
val sym = const.symbolValue
case EnumTag =>
val sym = const.symbolValue
val ownerName = internalName(sym.owner)
val fieldName = sym.javaSimpleName.toString
val fieldDesc = typeToBType(sym.tpe.underlying).descriptor
Expand Down Expand Up @@ -944,12 +945,21 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
mnode.visitVarInsn(asm.Opcodes.ALOAD, 0)
} else {
val mbt = symInfoTK(module).asClassBType
mnode.visitFieldInsn(
asm.Opcodes.GETSTATIC,
mbt.internalName /* + "$" */ ,
strMODULE_INSTANCE_FIELD,
mbt.descriptor // for nostalgics: typeToBType(module.tpe).descriptor
)
def visitAccess(container: ClassBType, name: String): Unit = {
mnode.visitFieldInsn(
asm.Opcodes.GETSTATIC,
container.internalName,
name,
mbt.descriptor
)
}
module.attachments.get[DottyEnumSingleton] match { // TODO [tasty]: dotty enum singletons are not modules.
case Some(enumAttach) =>
val enumCompanion = symInfoTK(module.originalOwner).asClassBType
visitAccess(enumCompanion, enumAttach.name)

case _ => visitAccess(mbt, strMODULE_INSTANCE_FIELD)
}
}
}

Expand Down