This avoids us using reserved identifiers as the enum case names of all
our underscored protocols like _ObjectiveCBridgeable. I used the
convention PROTOCOL_WITH_NAME to mirror how the known identifiers work.
Swift SVN r32924
Introduce a new constraint kind, BindParam, which relates the type of a
function parameter to the type of a reference to it from within the
function body. If the param type is an inout type, the ref type is an
lvalue type with the same underlying object type; otherwise the two
types must be the same. This prevents DeclRefExprs from being inferred
to have inout type in some cases.
<rdar://problem/15998821> Fail to infer types for closure that takes an inout argument
Swift SVN r32183
Introduce a new "OpenedGeneric" locator for when openGeneric opens a generic
decl into a plethora of constraints, and use this in CSDiags to distinguish
whether a constraint refers to an Expr as a whole or an "aspect" of the constraint.
Use that information in FailureDiagnosis::diagnoseGeneralConversionFailure
to know whether (as a fallback) we can correctly re-typecheck an entire expr
to obtain a missing type. If we are talking about an aspect of the expr, then
this clearly won't work.
The upshot of this is that where we previously compiled the testcase in 22519983
to:
y.swift:31:9: error: type '(inout _) -> Bool' does not conform to protocol 'RawRepresentable'
let a = safeAssign
^
we now produce the somewhat more useful:
y.swift:31:9: error: argument for generic parameter 'T' could not be inferred
let a = safeAssign
^
y.swift:27:6: note: in call to function 'safeAssign'
func safeAssign<T: RawRepresentable>(inout lhs: T) -> Bool {
^
Swift SVN r31620
bases. Consider this example (reduced from NameBinding/name_lookup.swift):
class ThisBase1 {
func baseFunc0() {}
}
class ThisDerived1 : ThisBase1 {
class func staticTestSelf1(a : ThisBase1) {
let x = self.baseFunc0
x(a)()
}
}
The type checker was incorrectly blasting over the self type of the 'self.baseFunc0'
reference, giving 'x' a type of "ThisDerived -> () -> ()" instead of the correct
type of "ThisBase -> () -> ()" and rejecting the testcase.
I'm not confident that this is the right fix, review greatly appreciated!
Swift SVN r30641
The isDependentType() query is woefully misunderstood. Some places
seem to want it to mean "a generic type parameter of dependent member
type", which corresponds to what is effectively a type parameter in
the language, while others want it to mean "contains a type parameter
anywhere in the type". Tease out these two meanings in
isTypeParameter() and hasTypeParameter(), respectively, and sort out
the callers.
Swift SVN r29945
... I have no idea why we were foolishly mapping such things to their
parent type, which made no sense whatsoever. Fixes
rdar://problem/21621421.
Swift SVN r29882
In r26737, Sema was changed to not wrap Self occurring in a protocol
extension in a DynamicSelf. The commit message was rather terse but
I believe this is because the metadata for Self is bound to the static
base type, not the runtime base type.
However, we still need to substitute Self in the return type for the
static base type in the case where the base is an existential,
otherwise we get an open existential type leaking out.
Also remove the default argument for replaceCovariantResultType(),
every call site passed in a value and it seems bad to omit it on
accident.
Fixes <rdar://problem/21433694>.
Swift SVN r29802
We were dropping *all* constraints on the Self type when forming
constraints from a protocol member, which included the extra
constraints provided by constrained extensions. Only drop the actual
protocol in which the member occurs (or the protocol extended by the
containing extension).
Fixes rdar://problem/21401180 and the 8 dupes I've found so far.
Swift SVN r29708
We diagnose usage of invalid existential types but we might still
try to compute substitutions. Just whip up an ErrorType instead.
Fixes <rdar://problem/16803384>.
Swift SVN r29567
lvalues when compiling list of partial-match overloads in diagnosis.
(This is a reapplication of commits r29462 and r29469.)
Also, fix the following tests:
stdlib/FixedPointDiagnostics.swift.gyb
stdlib/NumericDiagnostics.swift.gyb
<rdar://problem/17875634> can't append to array of tuples
Swift SVN r29493
This reverts commit r29462 because it looks like it breaks the following
tests:
Swift :: stdlib/FixedPointDiagnostics.swift.gyb
Swift :: stdlib/NumericDiagnostics.swift.gyb
Swift SVN r29484
Always rewrite the Self type to the base type. Previously we only
did it if the method had a dynamic self return. This caused some
confusing behavior in this case:
class C {
func m1() {}
func m2() -> Self {}
}
class D : C {}
The types of D.m1 and D.m2 are:
- D.m1: C -> () -> ()
- D.m2: D -> () -> D
For protocols, this also meant that the type of an instance method
reference P.f had an open existential that could "leak out" of
the OpenExistentialExpr. Now, P.f will have type P -> ... -> ...,
however using such a reference still crashes, just in SILGen
instead of Sema, because we don't generate the right thunks yet.
Progress on <rdar://problem/21289579>.
Swift SVN r29447
Special-casing these as MemberRefExprs created an asymmetry
where unbound archetype instance methods (<T : P> T.f) could
not be represented. Treating class and protocol methods
uniformly also eliminates a handful of special cases around
MemberRefExpr.
SILGen's RValue and call emission peepholes now have to know
about DeclRefExprs that point to protocol methods.
Finally, generalize the diagnostic for partially applied
mutating methods to any partially applied function with an
inout parameter, since this is not supported.
Fixes <rdar://problem/20564672>.
Swift SVN r29298
variable has the must-be-materializable bit set if the old one does.
When assigning a fixed type to a type variable that must be
materializable, transfer the bit to any type variables within the fixed
type, as appropriate.
Add Options field to SavedTypeVariableBinding to save/restore type
variable options during solution.
<rdar://problem/21026806> Propagate MustBeMaterializable bit among type variables appropriately
Swift SVN r28883
Add a new option, TVO_MustBeMaterializable, to
TypeVariableType::Implementation, and set it for type variables
resulting from opening a generic type. This solution isn't complete (we
don't yet copy the non-materializable bit on unification of type
variables, and it's possible to bind a must-be-materializable type
variable to a type with type variables that later get bound to
non-materializable types) but it addresses all reported crashes for this
issue.
<rdar://problem/20807269> Crash in non-materializable type
Swift SVN r28792
Fix a nullptr dereference when looking for a base expression
in a member access. Remove use of Optional<T*>, it wasn't providing
any value versus nullptr checking.
Swift SVN r28648
When in an initializer, we allow setting into immutable properties
provided that the type of base in `base.member` matches that of that
initializer's containing type. This was an approximation for allowing
full access into `self` during initialization but this doesn't work when
passing in a different struct of the same type because that struct
should be still be immutable.
Check whether the base of the member access is the implicit self
parameter of the initializer before allowing mutation.
rdar://problem/19814302
Swift SVN r28634
When performing unqualified lookup within a type context (or method
thereof) that is a protocol or a protocol extension, use the Self
archetype of the protocol or extension so we look in types implied by
the requirements as well. Part of rdar://problem/20509152, fixing the
example provided in rdar://problem/20694545.
Swift SVN r28363
In addition to being better for performance in these cases, this disables the "self."
requirement in these blocks. {}() constructs are often used to work around statements
that are not exprs in Swift, so they are reasonably important.
Fixing this takes a couple of pieces working together:
- Add a new 'extraFunctionAttrs' map to the ConstraintSystem for solution
invariant function attributes that are inferred (like @noescape).
- Teach constraint simplification of function applications to propagate
@noescape between unified function types.
- Teach CSGen of ApplyExprs to mark the callee functiontype as noescape
when it is obviously a ClosureExpr.
This is a very limited fix in some ways: you could argue that ApplyExpr should
*always* mark its callee as noescape. However, doing so would just introduce a
ton of function conversions to remove it again, so we don't do that.
Swift SVN r27723
Add syntax "[#Color(...)#]" for object literals, to be used by
Playgrounds for inline color wells etc. The arguments are forwarded to
the relevant constructor (although we will probably change this soon,
since (colorLiteralRed:... blue:... green:... alpha) is kind of
verbose). Add _ColorLiteralConvertible and _ImageLiteralConvertible
protocols, and link them to the new expressions in the type checker.
CSApply replaces the object literal expressions with a call to the
appropriate protocol witness.
Swift SVN r27479
This doesn't actually break the circular type-checking issues with
have with associated type inference, but it makes them less
painful. Fixes rdar://problem/20549165.
While here, and as a test, remove the _prext_underestimateCount
workound from the library. _CollectionDefaultsType now refines
_SequenceDefaultsType.
Swift SVN r27368
Consistently open all references into existentials into
opened-existential archetypes within the constraint solver. Then,
during constraint application, use OpenExistentialExprs to record in
the AST where an existential is opened into an archetype, then use
that archetype throughout the subexpression. This simplifies the
overall representation, since we don't end up with a mix of operations
on existentials and operations on archetypes; it's all archetypes,
which tend to have better support down the line in SILGen already.
Start simplifying the code in SILGen by taking away the existential
paths that are no longer needed. I suspect there are more
simplifications to be had here.
The rules for placing OpenExistentialExprs are still a bit ad hoc;
this will get cleaned up later so that we can centralize that
information. Indeed, the one regression in the compiler-crasher suite
is because we're not closing out an open existential along an error
path.
Swift SVN r27230
Previously, we were only opening the existentials as part of
constraint application, which involved some ugly, redundant code. This
should be NFC because it's just moving the existential opening
operation earlier, but it's a step toward opening up all existential
references.
Swift SVN r27190
To use members of protocol extensions on existential types, we
introduce an OpenExistentialExpr expression to open up the existential
type (into a local archetype) and perform the operations on that local
archetype.
Unlike with uses of initializers or dynamic-Self-producing
methods of protocols, which produce similar ASTs, we have the type
checker perform the "open" operation and then track it through
constraint application. This scheme is better (because it's more
direct), but it's still using a simplistic approach to deciding where
the actual OpenExistentialExpr goes that needs improvement.
Swift SVN r26964
Remove the semantic restrictions that prohibited extensions of
protocol types, and start making some systematic changes so that
protocol extensions start to make sense:
- Replace a lot of occurrences of isa<ProtocolDecl> and
dyn_cast<ProtocolDecl> on DeclContexts to use the new
DeclContext::isProtocolOrProtocolExtensionContext(), where we want
that behavior to apply equally to protocols and protocol extensions.
- Eliminate ProtocolDecl::getSelf() in favor of
DeclContext::getProtocolSelf(), which produces the appropriate
generic type parameter for the 'Self' of a protocol or protocol
extension. Update all of the callers of ProtocolDecl::getSelf()
appropriately.
- Update extension validation to appropriately form generic
parameter lists for protocol extensions.
- Methods in protocol extensions always use the witnesscc calling
convention.
At this point, we can type check and SILGen very basic definitions of
protocol extensions with methods that can call protocol requirements,
generic free functions, and other methods within the same protocol
extension.
Regresses four compiler crashers but improves three compiler
crashers... we'll call that "progress"; the four regressions all hit
the same assertion in the constraint system that will likely be
addressed as protocol extensions starts working.
Swift SVN r26579
Previously, we were reconstructing this mapping from the "full" opened
type produced by declaration references. However, when dealing with
same-type constraints between associated types and type parameters, we
could end up with an incomplete mapping, which let archetypes slip
through. Most of the churn here is sorting out the locators we need to
use to find the opened-type information. Fixes rdar://problem/18208283
and at least 3 dupes of it that I've found so far.
Swift SVN r25375
with more explicit/semantic conversions in and out.
Using a PointerUnion with overlapping pointer types
is both error-prone and pretty close to illegible.
Swift SVN r24707