| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
In Scala there are some methods that only exist in symbol tables,
but don't have corresponding method entries in Java class files.
To the best of my knowledge, these methods can be subdivided into five groups:
1) stuff weaved onto Any, AnyVal and AnyRef (aka Object),
2) magic methods that Scala exposes to fix Java arrays,
3) magic methods declared on Scala primitive value classes,
4) compile-time methods (such as classOf and all kinds of macros),
5) miscellaneous stuff (currently only String_+).
To support these magic symbols, I've modified the `checkMemberOf` validator
to special case Any/AnyVal/AnyRef methods and adjusted MethodMirror and
ConstructorMirror classes to use special invokers for those instead of
relying on Java reflection.
Support for value classes will arrive in the subsequent commit, because
it requires some unrelated changes to the mirror API (currently mirrors
only support AnyRefs as their targets).
|
|\
| |
| | |
SI-6188
|
| | |
|
| | |
|
|\ \
| |/
|/| |
SI-6175 reflect over classes with symbolic names
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Top-level classes with symbolic names (having binary names like $colon$colon)
have previously been incorrectly treated as local classes by Scala reflection.
As a result they were loaded as if they weren't pickled (i.e. as Java classes).
Moreover this bug also had a more subtle, but more dangerous manifestation.
If such a class has already been loaded indirectly by unpickling another class
(which refers to it in its pickle) and then someone tried to load it explicitly
via classToScala, then it would be loaded twice (once as a Scala artifact and
once as a Java artifact). This is a short route to ambiguities and crashes.
The fix first checks whether a class with a suspicious name (having dollars)
can be loaded as a Scala artifact (by looking it up in a symbol table).
If this fails, the class is then loaded in Java style (as it was done before).
Ambiguous names that can be interpreted both ways (e.g. foo_$colon$colon)
are first resolved as Scala and then as Java. This prioritization cannot lead
to errors, because Scala and Java artifacts with the same name cannot coexist,
therefore loading a Scala artifact won't shadow a homonymous Java artifact.
|
|/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Instead of trying to serialize the entire universe and failing miserably
(which happens now), exprs and type tags will now serialize their creators
and deserialize into scala.reflect.basis.
Since creators produced by reification are not serializable right now,
serialization will crash. That's a small improvement over state of the art
functionality-wise, but it's a step forward robustness-wise.
Next step in this direction is generation of serialization code for creators.
Related issues: SI-5919 and SI-5908. Also see the discussion at scala-internals
http://groups.google.com/group/scala-internals/browse_thread/thread/ef63f8b5bd194c7c
|
|
|
|
| |
Removes the stubs left out to appease the old starr, fixes macro tests.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Added a bunch of test methods to symbols to cover public flags:
(e.g. isPrivate, isFinal, isOverride, isImplicit, etc). I'd argue that
the API duplication w.r.t flag sets is trumped by unified interface
to tests and better encapsulation.
Also updated the API to be easier to understand after prior exposure
to Java or .NET reflection APIs:
1) Added typeParams to TypeSymbol and ClassSymbol.
2) Renamed MethodSymbol.resultType to returnType.
3) Removed the distinction between MethodSymbol.params vs MethodSymbol.allParams
now we just have MethodSymbol.params: List[List[Symbol]].
|
|
|
|
|
|
|
|
| |
Adds informative toString for InstanceMirror, FieldMirror,
MethodMirror (for methods and constructors), ClassMirror and ModuleMirror.
Universe mirrors (e.g. JavaMirrors or compiler mirrors) already have good
toString methods that show their affiliation and/or classpaths.
|
|
|
|
|
|
|
| |
This renaming arguably makes the intent of `asType` more clear,
but more importantly it shaves 6 symbols off pervasive casts that
are required to anything meaningful with reflection API
(as in mirror.reflectMethod(tpe.member(newTermName("x")).asMethodSymbol)).
|
|
|
|
|
|
|
| |
1) Removed unnecessary (i.e. implementable with pattern matching) type APIs.
2) Renamed isHigherKinded to takesTypeArgs making it easier to understand.
2) typeParams and resultType have been moved from MethodType to MethodSymbol
Strictly speaking they are superfluous, but they are used very often.
|
|
|
|
|
|
| |
This works around SI-5736 that's been deemed too risky to be fixed in 2.10.0.
A reflection newbie will be unlikely to acquire a field symbol from its name,
but the `accessed` method provides an easy way to navigate to it from a getter.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Firstly this unifies the reflection API - now both decls and members
return Scope (not Scope and List[Symbol] as it were before).
Secondly this fixes SI-5732 without having to sort the result of members.
Type.members now returns Scope, a distinguished type, which has the
`sorted` method, which does the required sorting if necessary.
Also removes nonPrivateMembers and nonPrivateDeclarations to keep the API
minimalistic (as can be seen from their implementation in internal.Types
they are just members and decls with bridges and private members removed).
|
|\
| |
| | |
SI-5751 cleans up toolboxes for the release
|
| |
| |
| |
| |
| |
| |
| |
| | |
Removes the `freeTypes` parameters on `typeCheckExpr` and `runExpr`,
since we now have public `substituteTypes` on both trees and types.
Also implements long-awaited `inferImplicitValue` and `inferImplicitView`
(thanks to Miles Sabin for nudging me!)
|
|\ \
| |/
|/| |
Fixed maddening "..." lately in printed types.
|
| |
| |
| |
| |
| |
| | |
I screwed around with type printing for a long time and now I have
to be done, so I suggest we accept the imperfection in here for now
because it's still way ahead of "..." as types go.
|
|\ \
| | |
| | | |
SI-5866 Support casting null to value classes
|
| | |
| | |
| | |
| | | |
The fix now supports null.asInstanceOf[C] where C is a value class that wraps a primitive type.
|
|\ \ \
| | | |
| | | | |
ClassTag.Nothing now throws an exception
|
| |/ /
| | |
| | |
| | |
| | | |
Nothing is a bottom type, so it doesn't make much sense for it to have
a meaningful erasure (ClassTag.Nothing.runtimeClass).
|
|\ \ \
| | | |
| | | | |
Remove resolveOverloaded
|
| | |/
| |/|
| | |
| | | |
It was decided to remove it until the next release
|
|\ \ \
| |/ /
|/| | |
Fixed SI-5603. Early definitions now get transparent positions.
|
| |/
| |
| |
| |
| |
| | |
This includes a fix for a minor problem described in #594 -
ensureNonOverlapping still focuses on default position when outside of early defs.
Review by @dragos, @odersky.
|
|\ \
| |/
|/| |
IDE improvements, with particular focus on making worksheets work.
|
| |
| |
| |
| | |
Adds a raw string interpolator raw"..." which does not do any escape sequence processing.
|
| |
| |
| |
| |
| |
| | |
Added all the known cases of failing self-types. Added tests for symbol
access (SI-4601) as well which should now be fixed for all of the same cases
as well.
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Following this commit are reversions of three prior commits which
introduced difficulties of their own, plus extra tests for this
issue and SI-4601, all of which I pinched from jrudolph.
Maybe there was a good reason for some of the complicated code
related to this ticket. I took the naive position that if we avoided
generating a method call to a particular receiver if the receiver
has no such method, we would encounter fewer NoSuchMethodErrors.
I would believe one can construct a scenario which this doesn't
handle correctly, but it's hard to believe this isn't a big
improvement. Review by @jrudolph, @odersky.
|
|/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
An extractor pattern `X(p)` should type check for any `X.unapply`/`X.unapplySeq`
that returns an `Option[_]` -- previously we were confused about the case where
it was an `Option[(T1, ... , Tn)]`. In this case, the expected type for the
pattern `p` is simply `(T1, ... , Tn)`.
While I was at it, tried to clean up unapplyTypeList and friends (by replacing them by extractorFormalTypes).
From the spec:
8.1.8 ExtractorPatterns
An extractor pattern x(p1, ..., pn) where n ≥ 0 is of the same syntactic form as a constructor pattern.
However, instead of a case class, the stable identifier x denotes an object which has a member method named unapply or unapplySeq that matches the pattern.
An unapply method in an object x matches the pattern x(p1, ..., pn) if it takes exactly one argument and one of the following applies:
n = 0 and unapply’s result type is Boolean.
n = 1 and unapply’s result type is Option[T], for some type T.
the (only) argument pattern p1 is typed in turn with expected type T
n > 1 and unapply’s result type is Option[(T1, ..., Tn)], for some types T1, ..., Tn.
the argument patterns p1, ..., pn are typed in turn with expected types T1, ..., Tn
|
|
|
|
| |
Sharpens the test so that only Object_== and Object_!= methods on valueclasses may be rewritten in posterasure, whereas user-defined methods are not rewritten.
|
|\
| |
| | |
Removes redundant outers
|
| |
| |
| |
| |
| |
| | |
Widens the criterion when outer fields can be omitted. It used to be that sub- and superclass had to be enclosed by the same outer class. Only in that case was the outer field of the class omitted. We now omit if subclass is contained in an outer class that is itself a subclass of the superclasses outer class.
See test case "outertest.scala" for an example.
|
|\ \
| | |
| | | |
Fix for SI-5385.
|
| | |
| | |
| | |
| | |
| | | |
Nodes which hit EOF with no whitespace afterward had
wrong position.
|
|\ \ \
| | | |
| | | | |
Implement @static annotation on singleton object fields.
|
| | | | |
|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
This commit introduces the `@static` annotation on fields of static singleton objects.
A static singleton object is a top-level singleton object or an object nested within
a static singleton object.
The field annotated with `@static` is generated as a true static field in the companion
class of the object. The initialization of the field is done in the static initializer of the
companion class, instead of the object itself.
Here's an example. This:
object Foo {
@static val FIELD = 123
}
class Foo
generates :
object Foo {
def FIELD(): Int = Foo.FIELD
}
class Foo {
<static> val FIELD = 123
}
The accessor in `object Foo` is changed to return the static
field in `class Foo` (the companion class is generated if it is
not already present, and the same is done for getters if `FIELD`
is a `var`).
Furthermore, all the callsites to accessor `Foo.FIELD` are rewritten
to access the static field directly.
It is illegal to annotate a field in the singleton object as `@static` if there is
already a member of the same name in `class Foo`.
This allows better Java interoperability with frameworks which rely on static fields being
present in the class.
The `AtomicReferenceFieldUpdater`s are one such example. Instead of having
a Java base class holding the `volatile` mutable field `f` and a static field containing
a reference to the `AtomicReferenceFieldUpdater` that mutates `f` atomically,
and extending this Java base class from Scala, we can now simply do:
object Foo {
@static val arfu = AtomicReferenceUpdater.newUpdater(
classOf[Foo], classOf[String], "f"
)
}
class Foo {
@volatile var f = null
import Foo._
def CAS(ov: String, nv: String) = arfu.compareAndSet(this, null, "")
}
In summary, this commit introduces the following:
- adds the `@static` annotation
- for objects without a companion class and `@static` members, creates a companion class
(this is done in `CleanUp`)
- checks for conflicting names and if `@static` is used on static singleton object member
- creates the `static` field in the companion class for `@static` members
- moves the field initialization from the companion object to the static initializer of
the class (the initialization of `@static` members is bypassed in the `Constructors` phase,
and added to static ctors in `CleanUp`)
- all callsites to the accessors of `@static` are rewritten to access the static fields directly
(this is done in `GenICode`)
- getters and setters to `@static` fields access the static field directly, and the field in the
singleton object is not emitted (this is done in `GenICode`)
- changes in `GenJVM`, `GenASM` - now computing local var indices in static initializers
as well - this was an oversight before, now is necessary
Future work: allow the `@static` annotation on methods as well - this will
be added in a future commit.
Review by @odersky, @dragos, @paulp, @heathermiller.
|
|\ \ \ \
| | | | |
| | | | | |
SI-6104 support This pattern
|
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | |
This(name) is treated just like Ident(name)
apparently this pattern was used in 2.9 code,
though I'm not sure it's spec'ed
|
|\ \ \ \ \
| | | | | |
| | | | | | |
SI-5999 consistent behavior for c.reify and c.universe.reify
|
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | | |
After a discussion on a reflection meeting on Jul 17
we concluded that we should split staticModule into
staticModule and staticPackage to remove the ambiguity
between packageless objects and packageless packages
(more in the comments in the body of the commit).
The motivation is verbosely outlined in the comments,
but the bottom line is that Scala allows packages and
packageless objects to have the same name within the same program.
Therefore at times we need to disambiguate, hence the introduction
of the staticPackage method.
As of such staticModule no longer works for packages.
In the same fashion staticPackage doesn't work for modules.
This is done to ensure robustness of reification.
I would like to do the same for getModule in Definitions,
but we have to maintain backward compatibility. That's why I retained
the old behavior, but replaced getModule invocations with getPackage
where appropriate to be in line with staticModule and staticPackage.
Another important thing that follows from the discussion is that
both staticClass and staticModule prefer parent packages over parent objects
in cases of ambiguity. Say, if we have the following snippet of code:
object B { class C } next to package B { class C }
then staticClass("B.C") will never even consider a C inside the object B.
This is how scalac operates, so we decided to be consistent here.
Finally reification logic got changed to distinguish between
staticModule and staticPackage, and to allow for the fact that
staticClass and staticModule prefer parent packages to parent objects.
|
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | | | |
Currently there are discrepancies between the behavior of
c.reify and c.universe.reify.
First step in fixing these problems is removing the duplication in the API.
That's why I'm cutting away the Context.reify shortcut.
Context.reify is a magic macro, hardwired in the fast track mechanism, so
removing it requires redeploying the starr (because an old starr will
crash if launched on sources that don't contain Context.reify).
To cleanly redeploy a starr I've left a Context.reify stub in sources,
but hidden it behind a `protected` modifier. When starr is redeployed
(in a subsequent commit) the stub will be removed.
I've also updated the tests to use c.universe.reify instead of c.reify.
This will break some of them, because c.universe.reify uses a standard
compiler mirror, which unlike a macro mirror doesn't like packageless classes.
That's an annoyance, but I think having clean separation of commits
is more important that being 100% consistent.
|
|\ \ \ \ \ \
| | | | | | |
| | | | | | | |
SI-5856 enables use of $this in string interpolation
|
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | | |
This pull request fixes SI-5856. The scanner has been modified
to return the correct token if keywords appear in $-expressions.
The parser has been modified to issue an error and to only accept
$<identifier>, $this and $block.
|
|\ \ \ \ \ \ \
| |_|/ / / / /
|/| | | | | | |
SI-5739 store sub-patterns in local vals
|
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | |
| | | | | | | |
Also closes SI-5158 (debuggability), SI-6070 (soundness).
To improve both debuggability and soundness,
we now store the result of an extractor (user-defined and synthetic)
in local variables.
For the case class case, this also fixes the soundness bug SI-6070,
as this prevents post-match mutation of bound variables.
The core of the refactoring consisted of introducing the PreserveSubPatBinders
trait, which introduces local variables instead of substituting symbols
for the RHS of those variables (so this can be seen as reverting the premature optimization
of inline the case-class getters into the case body).
Since TreeMakerToCond fuses the substitutions performed in a match to find out
which symbolic values binders evaluate to, masquerade PreserveSubPatBinders's
binding of subPatBinders and subPatRefs as the corresponding substitution.
Consider `case class Foo(bar: Int)`, then `case y@Foo(x) => println(x)`
gives rise to `{val x = y.bar; println(x)}` (instead of `println(y.bar)`),
and `subPatternsAsSubstitution` pretends we still replace `x` by `y.bar`,
instead of storing it in a local variable so that the rest of the analysis need not be modified.
Misc notes:
- correct type for seq-subpattern
- more error resilience (ill-typed patterns sometimes slip past the typechecker -- reopened SI-4425)
TODO: come up with a more abstract framework for expressing bound symbols and their values
|
|\ \ \ \ \ \ \
| | | | | | | |
| | | | | | | | |
fixes field mirrors and also improves docs and exceptions for all mirrors
|