Commit Graph

557 Commits

Author SHA1 Message Date
Xi Ge
1604c4ba9e [ClangImporter] Import variadic C functions as unavailable functions instead of ignoring them. rdar://16677468
Also, this helps us fix rdar://20092567.

Swift SVN r32903
2015-10-27 00:29:44 +00:00
Doug Gregor
44e34850ae Omit needless words: give initial Boolean parameters argument labels.
When the first parameter of a function has Boolean type, try to create
an argument label for it. We start with the (normally non-API)
parameter name as the argument label, then try to match that against
the end of the base name of the method to eliminate redundancy. Add a
little magic, and here are some diffs:

    -  func openUntitledDocumentAndDisplay(_: Bool) throws -> NSDocument
    +  func openUntitledDocument(display _: Bool) throws -> NSDocument

    -  func fontMenu(_: Bool) -> NSMenu?
    -  func fontPanel(_: Bool) -> NSFontPanel?
    +  func fontMenu(create _: Bool) -> NSMenu?
    +  func fontPanel(create _: Bool) -> NSFontPanel?

    -  func lockFocusFlipped(_: Bool)
    +  func lockFocus(flipped _: Bool)

    -  func rectForSearchTextWhenCentered(_: Bool) -> NSRect
    +  func rectForSearchText(whenCentered _: Bool) -> NSRect

    -  func dismissPreviewAnimated(_: Bool)
    -  func dismissMenuAnimated(_: Bool)
    +  func dismissPreview(animated _: Bool)
    +  func dismissMenu(animated _: Bool)

Swift SVN r32392
2015-10-01 23:34:21 +00:00
Doug Gregor
3a5a540b4c Add GenericSignature APIs to query the requirements on dependent types.
Extend GenericSignature to be able to answer queries about the
requirements placed on dependent types, e.g, are the class-bound, to
what protocols must they conform, etc. Implement this using a
lazily-created ArchetypeBuilder on the canonical generic signature.

NFC and as-yet-untested; this is staging for reducing our dependence
on the "all archetypes" list.

Swift SVN r32340
2015-09-30 18:17:31 +00:00
Doug Gregor
ff03d2ce09 Move more GenericSignature method implementations in GenericSignature.cpp NFC
Swift SVN r32339
2015-09-30 18:17:18 +00:00
Doug Gregor
0b2b0df907 Clean up canonicalization of GenericSignatures. NFC
GenericSignature's factory method determining whether the signature
was canonical based solely on whether the types in the parameters and
requirments were canonical. While that is currently true (for legacy
reasons), it is wrong: canonicalization also needs to canonicalize
requirements, including same-type requirements, as is currently done
in the canonical signature "for mangling". Move the "this is
canonical" dependency to the point where the canonical signature is
actually computed, so we can change the definition of canonical
signatures later.

While we're here, don't eagerly compute the canonical generic
signature in GenericSignature::getASTContext().

Swift SVN r32309
2015-09-29 22:05:47 +00:00
Xi Ge
c73a4e1509 [CodeComplete] Teach type context analyzer to analyzer for each statement. rdar://22831848
When completing at the sequence position of for each statment (for i in <HRER> {}),
values of sequence type should have higher priority than the rest.

Swift SVN r32202
2015-09-24 17:47:20 +00:00
Slava Pestov
3803938419 AST: Get some @objc tests (stupidly) passing on Linux again
Of course, the real fix is to split off the @objc parts of these
tests.

Fixes <rdar://problem/21745434>.

Swift SVN r31780
2015-09-08 22:12:16 +00:00
Chris Willmore
9c1f3e907a Revert "Transform EditorPlaceholderExpr into trap if executed in playground mode."
This reverts commit r31481, which apparently needed some parallel
changes to SourceKit and broke the build as a result.

Swift SVN r31483
2015-08-26 05:28:04 +00:00
Chris Willmore
0addd80bb3 Transform EditorPlaceholderExpr into trap if executed in playground mode.
Allow untyped placeholder to take arbitrary type, but default to Void.
Add _undefined<T>() function, which is like fatalError() but has
arbitrary return type. In playground mode, merely warn about outstanding
placeholders instead of erroring out, and transform placeholders into
calls to _undefined(). This way, code with outstanding placeholders will
only crash when it attempts to evaluate such placeholders.

<rdar://problem/21167372> transform EditorPlaceholderExpr into fatalError()

Swift SVN r31481
2015-08-26 04:50:55 +00:00
Slava Pestov
e416bfbc4e SILGen: Refactor code for existentials
We need to be able to introduce and eliminate existentials inside
reabstraction thunks, so make this logic independent of RValue
and Expr emission.

NFC for now.

Swift SVN r31375
2015-08-21 02:26:57 +00:00
Chris Lattner
e254d179c8 RecursiveTypeProperties is a bitfield, so its core operations are & and |, not - and +.
Resyntax them, NFC.


Swift SVN r31133
2015-08-11 16:57:13 +00:00
Chris Lattner
a899872d91 Reapply r31105, with some fixes to invalid unconstrained generics. These fixes correct
the regressions that r31105 introduced in the validation tests, as well as fixing a number
of other validation tests as well.

Introduce a new UnresolvedType to the type system, and have CSDiags start to use it
as a way to get more type information out of incorrect subexpressions.  UnresolvedType
generally just propagates around the type system like a type variable:
 - it magically conforms to all protocols
 - it CSGens as an unconstrained type variable.
 - it ASTPrints as _, just like a type variable.

The major difference is that UnresolvedType can be used outside the context of a
ConstraintSystem, which is useful for CSGen since it sets up several of them to 
diagnose subexpressions w.r.t. their types.

For now, our use of this is extremely limited: when a closureexpr has no contextual
type available and its parameters are invalid, we wipe them out with UnresolvedType
(instead of the previous nulltype dance) to get ambiguities later on.

We also introduce a new FreeTypeVariableBinding::UnresolvedType approach for
constraint solving (and use this only in one place in CSDiags so far, to resolve
the callee of a CallExpr) which solves a system and rewrites any leftover type 
variables as UnresolvedTypes.  This allows us to get more precise information out,
for example, diagnosing:

 func r22162441(lines: [String]) {
   lines.map { line in line.fooBar() }
 }

with: value of type 'String' has no member 'fooBar'
instead of: type of expression is ambiguous without more context

This improves a number of other diagnostics as well, but is just the infrastructural
stepping stone for greater things.





Swift SVN r31130
2015-08-11 06:06:05 +00:00
Chris Lattner
2204dbcbfd revert r31105, it causes some regressions on validation tests.
Swift SVN r31107
2015-08-10 15:01:22 +00:00
Chris Lattner
de79b60c89 Introduce a new UnresolvedType to the type system, and have CSDiags start to use it
as a way to get more type information out of incorrect subexpressions.  UnresolvedType
generally just propagates around the type system like a type variable:
 - it magically conforms to all protocols
 - it CSGens as an unconstrained type variable.
 - it ASTPrints as _, just like a type variable.

The major difference is that UnresolvedType can be used outside the context of a
ConstraintSystem, which is useful for CSGen since it sets up several of them to 
diagnose subexpressions w.r.t. their types.

For now, our use of this is extremely limited: when a closureexpr has no contextual
type available and its parameters are invalid, we wipe them out with UnresolvedType
(instead of the previous nulltype dance) to get ambiguities later on.

We also introduce a new FreeTypeVariableBinding::UnresolvedType approach for
constraint solving (and use this only in one place in CSDiags so far, to resolve
the callee of a CallExpr) which solves a system and rewrites any leftover type 
variables as UnresolvedTypes.  This allows us to get more precise information out,
for example, diagnosing:

 func r22162441(lines: [String]) {
   lines.map { line in line.fooBar() }
 }

with: value of type 'String' has no member 'fooBar'
instead of: type of expression is ambiguous without more context

This improves a number of other diagnostics as well, but is just the infrastructural
stepping stone for greater things.



Swift SVN r31105
2015-08-10 06:18:27 +00:00
Xi Ge
c260dc810c [CodeCompletion] Add visible option set type to the code completion results of unresolved members.
Swift SVN r31083
2015-08-07 20:28:09 +00:00
Chris Willmore
7f12c9ffd5 [CodeCompletion] Add the initial support for code completing import declaration.
When a user invoke code completion after import keywords, the names of
visible top level clang modules were recommended for finishing the import decl.

(Undoing revert r30961 of r30957, which just required lockstep commit to
SourceKit -- cwillmore)

Swift SVN r30962
2015-08-03 21:08:32 +00:00
Chris Willmore
e4d1ac9c24 Revert "[CodeCompletion] Add the initial support for code completing import declaration."
This reverts r30957 because it broke the following tests on Jenkins:

    SourceKit :: CodeComplete/complete_open.swift
    SourceKit :: CodeComplete/complete_test.swift

<rdar://problem/22120345> swift-incremental-RA #8289 failed to build

Swift SVN r30961
2015-08-03 21:04:46 +00:00
Xi Ge
5e0014bcc4 [CodeCompletion] Add the initial support for code completing import declaration.
When a user invoke code completion after import keywords, the names of
visible top level clang modules were recommended for finishing the import decl.

Swift SVN r30957
2015-08-03 20:02:17 +00:00
Chris Lattner
a863f05b89 remove dead code.
Swift SVN r30863
2015-07-31 20:06:04 +00:00
Jordan Rose
cfe20537d6 Dependencies: Make sure we count redeclaration checking as a dependency.
Also, checking protocol conformances doesn't depend on any members, just the type.
We don't track dependencies on types separately from members right now, though,
so instead there's now a dummy dependency on 'deinit'.

Swift SVN r30288
2015-07-16 23:36:35 +00:00
Xi Ge
1ca854d04f Make Decl::isPrivateStdlibDecl() return true if the decl comes from the SwiftShims module.
rdar://20919984

Swift SVN r30230
2015-07-15 22:43:36 +00:00
Jordan Rose
5f4ad8722f Unmanaged<T> is ObjC-compatible if T is an Objective-C-compatible object type.
rdar://problem/16832080

Swift SVN r30079
2015-07-10 19:05:21 +00:00
Joe Groff
c749f51bcb Don't include class metatypes in the "canBeClass" bucket.
The stdlib uses this condition to recognize types that represent classes without representation changing, which isn't true for metatypes. They will natively be pointers to the Swift type metadata instead of the ObjC class object, so a conversion step is necessary. This doesn't directly fix container bridging, but it prevents the runtime from trying to bridge verbatim metatypes without first changing them to ObjC representation.

Swift SVN r29998
2015-07-08 23:23:49 +00:00
Slava Pestov
f21b67ffe9 Rip out usages of CFunctionPointer in the frontend, NFC
Swift SVN r29991
2015-07-08 20:24:06 +00:00
Slava Pestov
34ff1c8e6d AST: Whitelist certain types for bridging even when Foundation is not imported
This is a hack to prevent us from optimizing out certain casts from AnyObject.

Fixes <rdar://problem/21215099>.

Swift SVN r29970
2015-07-08 06:49:29 +00:00
Slava Pestov
12b393c6f2 AST: Clean up ASTContext::get*Decl() methods
Add getUIntDecl(), getFloatDecl() and getDoubleDecl(), change
getIntDecl() and getBoolDecl() to cache the result, and clean up
duplication. NFC

Progress on <rdar://problem/21215099>.

Swift SVN r29969
2015-07-08 06:49:29 +00:00
Slava Pestov
fd141bead9 Sema: Remove unused inExpression parameter from ASTContext::getBridgedToObjC(), NFC
Progress on <rdar://problem/21215099>.

Swift SVN r29968
2015-07-08 06:49:27 +00:00
Doug Gregor
3023a710fc Split TypeBase::isDependentType() into isTypeParameter() and hasTypeParameter().
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
2015-07-07 21:20:54 +00:00
Doug Gregor
c3a6bca7b2 Compute recursive properties of ReferenceStorageType.
We're not gaining anything by avoiding doing this computation; better
to get the right answer so we don't need to revisit this. NFC

Swift SVN r29944
2015-07-07 21:20:47 +00:00
Slava Pestov
0950afd561 AST: Tuple types with default arguments should not be materializable
We have no way of materializing such a value because we store the
default argument expression in the Decl and not in the Type.

Fixes <rdar://problem/20424776>.

Swift SVN r29921
2015-07-06 21:44:47 +00:00
Doug Gregor
9fe51033a4 Allow lazy resolution of nested archetypes within the archetype builder.
While the archetype builder is constructing archetypes, it eagerly
produces the set of nested archetypes for each archetype. If the
construction of any of those nested archetypes refers to another
archetype, we would fail unceremonerously with an assertion. Fill in
the nested type names (but not their actual types) eagerly, allowing
the actual types to be determined lazily.

This is plumbing for rdar://problem/21620908, which still trips an
unrelated assertion, preventing a useful testcase at this step.

Swift SVN r29841
2015-07-01 17:21:06 +00:00
Slava Pestov
665b870f7f Sema: Fix yet another crash when accessing nested types of an existential
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
2015-06-23 06:39:22 +00:00
Joe Groff
e57c470019 Introduce a "@box T" type for SIL.
Represents a heap allocation containing a value of type T, which we'll be able to use to represent the payloads of indirect enum cases, and also improve codegen of current boxes, which generates non-uniqued box metadata on every allocation, which is dumb. No codegen changes or IRGen support yet; that will come later.

This time, fix a paste-o that caused SILBlockStorageTypes to get replaced with SILBoxTypes during type substitution. Oops.

Swift SVN r29489
2015-06-18 15:21:52 +00:00
Mark Lacey
39087cd36b Revert "Introduce a "@box T" type for SIL."
This reverts commit r29474 because it looks like it is breaking the
build of the SpriteKit overlay.

Swift SVN r29482
2015-06-18 06:28:04 +00:00
Joe Groff
7b0045c790 Introduce a "@box T" type for SIL.
Represents a heap allocation containing a value of type T, which we'll be able to use to represent the payloads of indirect enum cases, and also improve codegen of current boxes, which generates non-uniqued box metadata on every allocation, which is dumb. No codegen changes or IRGen support yet; that will come later.

Swift SVN r29474
2015-06-18 04:07:03 +00:00
Slava Pestov
67a1f24d59 Sema: 'dynamic' attribute now diagnoses if Foundation is not imported
This prevents us from seeing a less useful error message from SILGen
further down the line.

Also fix a bug where @objc without importing Foundation was not diagnosed
after the first top-level form. Some tests were relying on this behavior,
so fix those tests, either by splitting off the objc parts of the test, or
just by passing the -disable-objc-attr-requires-foundation-module flag.

Fixes <rdar://problem/20660270>.

Swift SVN r29359
2015-06-10 01:18:27 +00:00
Jordan Rose
de81a3e15f Prefer using known-identifiers to using getIdentifier.
I didn't add anything to the table, just made use of what was already there.
We have plenty of additional calls to getIdentifier that could probably benefit
from this kind of easy access as well.

This commit also removes FOUNDATION_MODULE_NAME and OBJC_MODULE_NAME from
Strings.h. Neither of these is likely to change in the future, and both
already have KnownIdentifiers equivalents in use.

No intended functionality change.

Swift SVN r29292
2015-06-04 04:01:08 +00:00
Jordan Rose
2d66428272 Clean up KnownIdentifiers.def.
- Remove unused names.
- Define IDENTIFIER in terms of IDENTIFIER_WITH_NAME.
- Adjust each name to always match the corresponding value in case.
- Add an IDENTIFIER_ macro for the common case of defining an underscored name.
- Avoid creating names with double underscores, which are technically reserved
  by the C++ standard.

There are two special cases I left in here for the identifiers '_code' and
'_domain'. I didn't want to call these simply 'Id_code' and 'Id_domain' for
fear someone would try to use them as 'code' and 'domain', so I made them into
'Id_code_' and 'Id_domain_' for now.

No intended functionality change.

Swift SVN r29291
2015-06-04 04:01:06 +00:00
Doug Gregor
a3f01190f3 Fill in nested types of an opened existential type.
We only attempt to access such nested types in ill-formed code, but
this helps maintain AST invariants. Fixes rdar://problem/20593294 and
resolves 18 compiler crashers.

Swift SVN r29135
2015-05-29 05:47:28 +00:00
Doug Gregor
e33f4f65dd Validation for patterns involving unbound generic types must consider initializers.
Fixes rdar://problem/20577950.

Swift SVN r29124
2015-05-29 00:06:03 +00:00
Doug Gregor
74050648de Make @objc enums that conform to ErrorType also conform to _ObjectiveCBridgeableErrorType.
This allows @objc enum error types produced in Objective-C (e.g., via
+[NSError errorWithDomain:code:userInfo:]) to be bridged back to their
original enum types in Swift via pattern matching/catch blocks.

This finishes rdar://problem/20577517.

Swift SVN r28803
2015-05-20 00:16:39 +00:00
Doug Gregor
c60c6d9207 Dependent member types are always dependent.
Swift SVN r28794
2015-05-19 22:40:12 +00:00
John McCall
312a9c1f6e Clean up correctly if a variadic argument throws.
rdar://20942603

Swift SVN r28622
2015-05-15 08:20:36 +00:00
Andrew Trick
313c30ad58 Prohibit specialization on DynamicSelf type.
Fixes <rdar://problem/20044992> Swift: Generic functions called from
class methods with type parameter inferred to Self compiles, breaks
type system under optimization

If we don't prohibit specialization then we silently miscompile by
assuming a base class instead of the dynamic type.

It is unclear to me why GenericFunctionType did not inherit any
recursive type properties from it's arguments and result. However, it
I think it makes sense to propagate DynamicSelfType into
GenericFunctionType so I've broke with convention here.

Swift SVN r28541
2015-05-13 23:36:17 +00:00
Joe Groff
66e1f37e62 SILGen: Reabstraction for vtable entries.
When a derived class specializes its base class, e.g. 'class Derived: Base<Int>', the natural abstraction levels of its methods may differ from the original base class's more abstract methods. Handle this by using the reabstraction machinery to thunk values when necessary. Merge the existing optionality thunking support into the reabstraction code, where witness thunking and similar convention adjustments may also be able to use it, if we desire. Fixes rdar://problem/19760292.

Swift SVN r28505
2015-05-13 03:25:05 +00:00
Joe Groff
95d1cf5e6d Revert "ClangImporter etc.: Remap C vector types to nested BaseType.VectorN types."
Reverts r28087. We're going back to the C++ interface for SIMD, and the changes in this patch are needless complication for that design.

Swift SVN r28384
2015-05-09 23:03:33 +00:00
Doug Gregor
b5626942b4 When diagnostic Objective-C method conflicts, prefer decls with source locations.
It's possible (and likely!) that Objective-C method conflicts will
involve declarations with and without source locations. Make sure that
the first error has a property source location in such cases. Fixes
rdar://problem/20042769.

Swift SVN r28299
2015-05-07 22:44:33 +00:00
Ted Kremenek
9f9bb725cf Rename '_ErrorType' to 'ErrorType'.
Swift SVN r28293
2015-05-07 21:59:29 +00:00
Doug Gregor
b8995b0aa3 Transform the Module class into ModuleDecl.
Modules occupy a weird space in the AST now: they can be treated like
types (Swift.Int), which is captured by ModuleType. They can be
treated like values for disambiguation (Swift.print), which is
captured by ModuleExpr. And we jump through hoops in various places to
store "either a module or a decl".

Start cleaning this up by transforming Module into ModuleDecl, a
TypeDecl that's implicitly created to describe a module. Subsequent
changes will start folding away the special cases (ModuleExpr ->
DeclRefExpr, name lookup results stop having a separate Module case,
etc.).

Note that the Module -> ModuleDecl typedef is there to limit the
changes needed. Much of this patch is actually dealing with the fact
that Module used to have Ctx and Name public members that now need to
be accessed via getASTContext() and getName(), respectively.

Swift SVN r28284
2015-05-07 21:10:50 +00:00
Joe Groff
e7547adabd AST: Initial work to canonicalize generic signatures for mangling.
Currently GenericSignature::getCanonicalSignature isn't able to canonicalize the set of requirements due to fragile dependencies on generic signatures matching AllArchetypes order of their originating GenericParamLists. However, we shouldn't let that stop us from getting the mangling right, so implement a "getCanonicalManglingSignature" that builds the true canonical signature by feeding it into an ArchetypeBuilder and shedding unnecessary constraints. For now, just handle conformance and base class constraints; still to do are same-type constraints.

Swift SVN r28191
2015-05-06 01:29:15 +00:00