Commit Graph

9699 Commits

Author SHA1 Message Date
Slava Pestov
c360c82850 AST: Automatically create the 'self' parameter when needed
Parsed declarations would create an untyped 'self' parameter;
synthesized, imported and deserialized declarations would get a
typed one.

In reality the type, if any, depends completely on the properties
of the function in question, so we can just lazily create the
'self' parameter when needed.

If the function already has a type, we give it a type right there;
otherwise, we check if a 'self' was already created when we
compute a function's type and set the type of 'self' then.
2018-08-25 10:44:55 -07:00
Slava Pestov
7f2787eece AST: Lazily compute initializer interface type 2018-08-25 02:58:49 -07:00
Slava Pestov
e78f16fb69 AST: ProtocolConformance::subst() doesn't need to take substType 2018-08-25 00:31:07 -07:00
Pavel Yaskevich
5ca770059f Merge pull request #18935 from xedin/properly-diagnose-ambiguities-with-fixes
[ConstraintSystem] Diagnose ambiguities related to solutions with fixes
2018-08-24 17:34:11 -07:00
Xi Ge
6adac7a1e3 DiagnosticEngine: require clients to explicitly specify source locations when emitting diagnostics. NFC (#18962) 2018-08-24 16:14:16 -07:00
Robert Widmann
832307c30a Merge pull request #17764 from CodaFi/irreconcilable-spatial-differences
[Space Engine] Remove the @_downgrade_exhaustivity_check hack
2018-08-24 14:00:33 -07:00
Xi Ge
e4388af6be swift-module-digester: refactor the ABI/API diagnostics to use DiagnosticEngine. NFC (#18957)
Before this patch, we used to define tooling-specific diagnostics. With adding more
checking logics, we found this mechanism hard to extend. This patch
eliminates the home-made diagnostics model to use the one from compiler, which provides
several benefits: less boiler-templates, better integration with DiagnosticConsumer,
and easy ordering of detected issues.
2018-08-24 13:11:32 -07:00
Robert Widmann
d27765e984 Merge pull request #18904 from CodaFi/filling-the-void-within-my-soul
[SE-0155] Reject empty associated value lists
2018-08-24 12:29:56 -07:00
swift-ci
218f1e7d48 Merge pull request #18886 from ahoppen/rawsyntax-retain-arena 2018-08-24 12:27:37 -07:00
Pavel Yaskevich
16fc3117cc [ConstraintSystem] Diagnose ambiguities related to solutions with fixes
If all of the solutions in the set have a single fix, which points
to the common anchor, attempt to diagnose the failure as an
ambiguity with a list of candidates and their related problems as notes.

Having richer message like that helps to understand why something is
ambiguous e.g. if there are two overloads, one requires conformance
to some protocol and another has a same-type requirement on some type,
but neither matched exactly, having both candidates in the diagnostic
message with associated errors, instead of simplify pointing to related
declarations, helps tremendously.
2018-08-24 11:20:49 -07:00
Pavel Yaskevich
eefbb1547c [Diagnostics] Implement diagnostic-as-note for requirement failures 2018-08-24 11:20:49 -07:00
Robert Widmann
2fb5afb755 Remove the @_downgrade_exhaustivity_check hack
This hack was only needed for Swift 3 mode in a narrow case.  Flush it out of the compiler so we can simplify the space engine.
2018-08-24 10:54:43 -07:00
Robert Widmann
e12fbc2aa2 Reject empty associated value lists
SE-0155 makes an empty associated value list in an enum element
declaration illegal.  Warn about this in legacy Swift mode, and reject
it otherwise.  This offers two fixes:
1) Remove the empty associated value list
2) Insert a 'Void' associated value
2018-08-24 10:50:23 -07:00
Alex Hoppen
66374a14ea [libSyntax] Make RawSyntax nodes hold a strong reference to their arena
This allows an elegant design in which we can still allocate RawSyntax
nodes using a bump allocator but are able to automatically free that
buffer once the last RawSyntax node within that buffer is freed.

This also resolves a memory leak of RawSyntax nodes that was caused by
ParserUnit not freeing its underlying ASTContext.
2018-08-24 08:39:54 -07:00
Johannes Weiss
bd2de10057 Builtin.isbitwisetakable 2018-08-24 16:03:38 +01:00
Doug Gregor
d1ea1813c9 [Type checker] Reimplement validation of @_specialize attribute.
Reimplement the validation of the @_specialize attribute to make use of
RequirementRequest::visitInherited() rather than performing ad hoc
validation.
2018-08-23 23:41:09 -07:00
Doug Gregor
872463d6c6 Merge pull request #18923 from DougGregor/where-requirement-request
[Type checker] Introduce a request to evaluate “where” clause requirements
2018-08-23 21:31:19 -07:00
Doug Gregor
3c54886c4d [Type checker] Use RequirementRequest::visitRequirements() more intentionally.
Rather than using RequirementRequest::visitRequirements() for its side
effects, then reading from the TypeLocs left behind, start eliminating
TypeLoc-based APIs so we pass Type and TypeRepr separately.

Add some utilities to dig into a possibly-null RequirementRepr* and dig
out the appropriate TypeReprs.
2018-08-23 15:14:19 -07:00
Doug Gregor
868f763406 [GSB] Ensure that we don’t pick a self-recursive requirement source.
When computing the conformance access path, make sure that we don’t pick
a self-recursive requirement source.
2018-08-23 14:20:25 -07:00
Erik Eckstein
7c06d4f8ab Remove the pinning built-ins.
They are not used anymore after removing the pinning adressors.
2018-08-23 12:47:56 -07:00
Erik Eckstein
6ba45473df Remove the pinning addressors
It was used for Array + related types.
With exclusivity checking the pinned addressors are not useful anymore.

rdar://problem/35401528
2018-08-23 12:47:56 -07:00
Doug Gregor
94951f431d [Lazy resolver] Remove resolveTrailingWhereClause().
This is completely subsumed by the “requirement” request.
Also remove some dead declarations in TypeChecker. NFC.
2018-08-23 09:28:33 -07:00
Doug Gregor
fcfd4c8a8c [Type checker] Introduce a request to evaluate “where” clause requirements.
Introduce a new form of request that produces the ith Requirement of the
where clause of a given entity, which could be a protocol, associated type,
or anything with generic parameters. The requirement can be evaluated
at any type resolution stage; the “interface” type stage will be cached
in the existing RequirementReprs.

Fixes SR-8119 / rdar://problem/41498944.
2018-08-23 09:25:58 -07:00
omochimetaru
c0114eaed4 [AST] explicit PrintOptions default constructor (#18142)
For use in LLDB.
2018-08-23 08:57:16 -07:00
Pavel Yaskevich
4fb95a859c Merge pull request #18916 from xedin/diagnostic-engine-cleanup
[DiagnosticEngine] NFC: Remove some code duplication in `diagnose`
2018-08-22 22:19:21 -07:00
Doug Gregor
8c58f2629d Merge pull request #18913 from DougGregor/inherited-type-stages
[Type checker] Introduce resolution stages for "inherited type" requests
2018-08-22 19:57:13 -07:00
Pavel Yaskevich
fb7d6a43f9 [DiagnosticEngine] NFC: Remove some code duplication in diagnose
Make it so there is only one underlying `diagnose` for `SourceLoc`
and `Decl *`, everything else should just be using them.
2018-08-22 18:27:30 -07:00
Doug Gregor
303805d551 [Type checker] Check generic parameter inheritance clauses later.
Move the checking of generic parameter inheritance clauses into the
DeclChecker, getting it out of signature computation and out of the
TypeChecker instance.
2018-08-22 16:17:52 -07:00
Doug Gregor
4b80872d48 [Type checker] Introduce stages for inherited type requests.
Extend the inputs to InheritedTypeRequest, SuperclassTypeRequest, and
EnumRawTypeRequest to also take a TypeResolutionStage, describing what
level of type checking is required. The GenericSignatureBuilder relies
only on structural information, while other clients care about the
full interface type.

Only the full interface type will be cached, and the contextual type
(if requested) will depend on that.
2018-08-22 15:29:08 -07:00
Mike Ash
3e4a5a2d79 [Runtime][ABI] Have swift_willThrow take the error value in the return register.
rdar://problem/37578477
2018-08-22 15:04:49 -04:00
John McCall
a30d91e3cb Implement vararg expansion well enough to support argument forwarding.
I needed this for materializeForSet remission, but it makes inherited
variadic initializers work, too.

I tried to make this a reasonable starting point for a real language
feature.  Here's what's still missing:

- syntax
- semantic restrictions to ensure that the expression isn't written in
  invalid places or arbitrarily converted
- SILGen support for expansions that aren't the only variadic argument

rdar://16331406
2018-08-22 06:46:08 -04:00
Harlan
096e6adb3f [TBDGen] Fix check for global accessors (#18883)
Previously, TBDGen skipped emitting lazy initializers for globals that
appeared in any file with an entry point. This breaks, however on files
that have an NSApplicationMain/UIApplicationMain class in them, where
the entry point is synthesized but top-level globals are not locally
scoped. This change re-uses SILGen's check and only skips variable
declarations that appear at top level in a script mode file.

Resolves rdar://43549749
2018-08-21 18:22:59 -07:00
Joe Groff
ae2a5cfef2 Merge pull request #18818 from ikesyo/remove-unused-error-diag
Remove now-unnecessary `expr_swift_keypath_unimplemented_component` diagnostic
2018-08-21 10:45:11 -07:00
Pavel Yaskevich
621204b7c6 Merge pull request #18870 from xedin/add-superclass-req-failure-diagnostic
[Diagnostics] Add `superclass` requirement fix/diagnostic
2018-08-21 09:16:41 -07:00
Pavel Yaskevich
16dfa6be72 [Diagnostics] Add superclass requirement fix/diagnostic
Extend new requirement failure diagnostics by adding "superclass"
generic requirement failures.
2018-08-21 00:39:21 -07:00
Slava Pestov
d245831fa2 Merge pull request #18694 from slavapestov/in-place-class-metadata-init
In-place class metadata initialization
2018-08-20 19:17:45 -07:00
Doug Gregor
7fa4f1df54 Merge pull request #18859 from DougGregor/type-resolution-stage
[Type Checker] Add TypeResolution(Stage) to describe type computations.
2018-08-20 18:44:31 -07:00
Joe Groff
d3bd01e8c8 Merge pull request #18804 from jckarter/identity-key-path
Runtime support for identity key paths.
2018-08-20 18:04:17 -07:00
Slava Pestov
4069fa68db Sema: Lift restriction on @objc categories of concrete subclasses of generic classes
In-place initialization means the class has a symbol we can reference
from the category, so there's nothing to do on the IRGen side.

For JIT mode, we just need to realize the class metadata by calling an
accessor instead of directly referencing the symbol though.
2018-08-20 16:23:07 -07:00
Pavel Yaskevich
b6d9dc65c6 Merge pull request #18819 from xedin/add-sametype-req-diagnostics
[ConstraintSystem] Add same-type requirement fix/diagnostic
2018-08-20 14:39:52 -07:00
Doug Gregor
560446058a [Type Checker] Add TypeResolution(Stage) to describe type computations.
Introduce an enum to describe the “stage” of type resolution that should
be performed, which is a notion that loosely exists within the type
checker already. Encapsulate the notion of a stage + the DeclContext
in which a type-check occurs into a new TypeResolution class, which
will replace the current GenericTypeResolver hierarchy.
2018-08-20 14:21:52 -07:00
Slava Pestov
4553916348 Merge pull request #18815 from slavapestov/sil-lowering-function-type
Refactor SIL type lowering to not use FunctionType::getOld()
2018-08-20 17:04:38 -04:00
Joe Groff
44b55ae197 Runtime support for identity key paths.
Make sure the implementation can handle a key path with zero components by removing inappropriate assumptions that the number of components is always non-empty. Identity key paths also need some special behavior:

- Appending an identity key path should be an identity operation for the other operand
- Identity key paths have a `MemoryLayout.offset(of:)` zero
- Identity key paths interop with KVC as key paths to `@"self"`

To be able to exercise and test this behavior, add a `Builtin.identityKeyPath()` function and `WritableKeyPath._identity` accessor in lieu of finalized syntax.
2018-08-20 14:00:46 -07:00
Doug Gregor
3499bf9d3a [Type checker] Eliminate the TypeChecker parameter from CompleteGenericTypeResolver. 2018-08-20 10:33:23 -07:00
John McCall
b2f20c063f Fix and improve DI diagnostics around inout uses of immutable constants.
The only real bug here is that we were looking specifically for `apply`
instructions, so we failed to diagnose `try_apply` calls to mutating
throwing functions on immutable existentials.  Fixing this is a
source-compatibility break, but it's clearly in the "obvious bug" category
rather than something we need to emulate.  (I found this bug because DI
stopped diagnosing a modification of a property of a `let` existential
when it started being done with `modify`, which of course is called with
`begin_apply`.)
2018-08-20 02:51:44 -04:00
Pavel Yaskevich
3cc613497c [ConstraintSystem] Add same-type requirement fix/diagnostic
Extend new requirement failure diagnostics by adding "same-type"
generic requirement failures.
2018-08-18 13:05:32 -07:00
Sho Ikeda
cb25a03bb1 Remove now-unnecessary expr_swift_keypath_unimplemented_component diagnostic 2018-08-18 15:45:43 +09:00
Slava Pestov
82fb98f99e AST: Remove Can{,Any,Generic}FunctionType::getOld() 2018-08-18 01:54:17 -04:00
Slava Pestov
a5ddd53227 Merge pull request #18812 from slavapestov/easy-function-type-conversions
Port almost all remaining FunctionType::get() usages to new representation
2018-08-18 00:11:52 -04:00
Slava Pestov
527ff375dc AST: Rename old form of {Generic,}FunctionType::get() to getOld()
This makes it easier to grep for and eventually remove the
remaining usages.

It also allows you to write FunctionType::get({}, ...) to call the
ArrayRef overload empty parameter list, instead of picking the Type
overload and calling it with an empty Type() value.

While I"m at it, in a few places instead of renaming just clean up
usages where it was completely mechanical to do so.
2018-08-17 19:28:17 -04:00