Commit Graph

1244 Commits

Author SHA1 Message Date
Slava Pestov
93c80da77c Parse: __shared and __owned should be contextual keywords
This was a source compatibility regression, someone actually had
an identifier named __shared.
2017-10-24 20:45:50 -07:00
Andrew Trick
d369aa4070 Support @noescape SIL function types. (#12420)
Support for @noescape SILFunctionTypes.

These are the underlying SIL changes necessary to implement the new
closure capture ABI.

Note: This includes a change to function name mangling that
primarily affects reabstraction thunks.

The new ABI will allow stack allocation of non-escaping closures as a
simple optimization.

The new ABI, and the stack allocation optimization, also require
closure context to be @guaranteed. That will be implemented as the
next step.

Many SIL passes pattern match partial_apply sequences. These all
needed to be fixed to handle the convert_function that SILGen now
emits. The conversion is now needed whenever a function declaration,
which has an escaping type, is passed into a @NoEscape argument.

In addition to supporting new SIL patterns, some optimizations like
inlining and SIL combine are now stronger which could perturb some
benchmark results.

These underlying SIL changes should be merged now to avoid conflicting
with other work. Minor benchmark discrepancies can be investigated as part of
the stack-allocation work.

* Add a noescape attribute to SILFunctionType.

And set this attribute correctly when lowering formal function types to SILFunctionTypes based on @escaping.

This will allow stack allocation of closures, and unblock a related ABI change.

* Flip the polarity on @noescape on SILFunctionType and clarify that
we don't default it.

* Emit withoutActuallyEscaping using a convert_function instruction.

It might be better to use a specialized instruction here, but I'll leave that up to Andy.

Andy: And I'll leave that to Arnold who is implementing SIL support for guaranteed ownership of thick function types.

* Fix SILGen and SIL Parsing.

* Fix the LoadableByAddress pass.

* Fix ClosureSpecializer.

* Fix performance inliner constant propagation.

* Fix the PartialApplyCombiner.

* Adjust SILFunctionType for thunks.

* Add mangling for @noescape/@escaping.

* Fix test cases for @noescape attribute, mangling, convert_function, etc.

* Fix exclusivity test cases.

* Fix AccessEnforcement.

* Fix SILCombine of convert_function -> apply.

* Fix ObjC bridging thunks.

* Various MandatoryInlining fixes.

* Fix SILCombine optimizeApplyOfConvertFunction.

* Fix more test cases after merging (again).

* Fix ClosureSpecializer. Hande convert_function cloning.

Be conservative when combining convert_function. Most of our code doesn't know
how to deal with function type mismatches yet.

* Fix MandatoryInlining.

Be conservative with function conversion. The inliner does not yet know how to
cast arguments or convert between throwing forms.

* Fix PartialApplyCombiner.
2017-10-17 13:07:25 -07:00
Slava Pestov
3255b49f03 Parse: Fix formatting 2017-09-20 00:07:05 -07:00
Slava Pestov
bf381cacab Parse: Set CurDeclContext correctly when parsing 'where' clauses
Make sure we construct the containing decl first, and push a
ContextChange before parsing a free-standing where clause.
2017-09-19 23:08:37 -07:00
John McCall
171d45d8c9 Move more of the signature validation of accessors into Sema.
Use this to remove the last bit of the hack to suppres noescape on setter
arguments.  Add a more comprehensive test of noescape's interaction with
accessors.
2017-09-13 01:11:00 -04:00
Xi Ge
560b08c171 SyntaxModel: simplify the collecting of contextual keywords in PrecedenceGroup.NFC (#11819) 2017-09-08 12:38:44 -07:00
Xi Ge
34e2aec662 Parser: use parser to generate a refined token stream to help syntax coloring. (#11809)
This patch allows Parser to generate a refined token stream to satisfy tooling's need. For syntax coloring, token stream from lexer is insufficient because (1) we have contextual keywords like get and set; (2) we may allow keywords to be used as argument labels and names; and (3) we need to split tokens like "==<". In this patch, these refinements are directly fulfilled through parsing without additional heuristics. The refined token vector is optionally saved in SourceFile instance.
2017-09-08 10:28:19 -07:00
Slava Pestov
9126d316d8 Parse: Remove parseTypeForInheritance()
We can just use parseType() everywhere instead. We already check
for non-identifier types in inheritance clauses elsewhere, and indeed
we have to anyway because an identifier type might resolve to a
type alias whose underlying type is a non-nominal type.

It doesn't look like this change made any diagnostics worse, but if
we find a case where it did, we could revert it.
2017-09-05 21:53:52 -07:00
Slava Pestov
3e2acb8ab0 Parse: Allow protocol compositions in all inheritance clauses
We allowed them for generic parameter inheritance clauses but
not anywhere else. While arguably this has stylistic benefits,
the restriction was not enforced consistently and was mostly a
result of implementation limitations.

Lift the restriction and fix things up where needed to make them
work. This brings us closer to allowing protocols to constrain
the 'Self' type to a subclass of a class by listing the class in
the protocol's inheritance clause, which was a feature from SE-0156,
but this doesn't quite work.

Fixes <https://bugs.swift.org/browse/SR-4678> and
<rdar://problem/31785092>.
2017-09-05 21:53:52 -07:00
Slava Pestov
19fed22872 Parse: Remove redundant diagnostic
We had two slightly different codepaths to diagnose ': class'
in an inheritance clause where it is not supported.

For generic parameters, we would fix the 'class' to 'AnyObject',
but for associated types we didn't do this. Perform the fix in
all cases where it makes sense and remove one of the two
diagnostics.
2017-09-05 21:53:52 -07:00
Slava Pestov
50e7c066f7 Parse: Simpler handling of 'class' in protocol inheritance list
Instead of treating this as its own thing, just parse it as if
the user wrote 'AnyObject'.
2017-09-04 17:52:34 -05:00
Jordan Rose
449cd98997 Excise "Accessibility" from the compiler (3/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

Rename AccessibilityAttr to AccessControlAttr and
SetterAccessibilityAttr to SetterAccessAttr, then track down the last
few uses of "accessibility" that don't have to do with
NSAccessibility. (I left the SourceKit XPC API alone because that's
supposed to be more stable.)
2017-08-28 13:27:59 -07:00
Jordan Rose
1c651973c3 Excise "Accessibility" from the compiler (2/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the 'Accessibility' enum to be named 'AccessLevel'.
2017-08-28 11:34:44 -07:00
Robert Widmann
76a4935d16 Staging for __consuming
Pushes __consuming through the frontend and extends existing
attribute-based diagnsotics to cover it.  Unlike `nonmutating`,
__consuming is allowed in class methods, though it makes little
sense to put it there.
2017-08-23 12:19:00 -07:00
Toni Suter
b825cdce4f [Parse] [SR-5674] Add fix-it for computed 'let' declaration (#11527) 2017-08-20 13:38:50 +09:00
Rintaro Ishizaki
a48a3ab715 [Parse] Cleanup leftovers after removing ForStmt (#11416)
* Remove unused PD_InLoop from ParseDeclFlags.
* Remove XFAIL-ed test file.
2017-08-10 13:13:05 +09:00
Ben Langmuir
ed05901941 [parser] Set CurDeclContext before parsing where clause in type decls
This simplifies code-completion by not having to make a belated call to
setParsedDecl() and seems more correct in general.
2017-08-02 12:55:58 -07:00
Ben Langmuir
46504db7a7 [code-completion] Partly fix completion of associatedtypes in where clauses
This gets us to the point where we will complete 'T' here:
    associatedtype T where #^A^#
And when completing here, we now at least find the correct declaration:
    associatedtype T: P where T.#^A^#

There is a remaining issue that in the second example we will not find
members of `P`; we seem to be missing the conformance from the archetype
we get for `T`.

rdar://problem/20582394
2017-08-01 14:16:03 -07:00
swift-ci
17ddc5802f Merge pull request #10965 from ahoppen/deinit-special-name 2017-08-01 07:50:00 -07:00
Ben Langmuir
534c0cc2cb [code-completion] Generic where clauses
Complete generic parameters and their members inside generic where
clauses on structs, classes, enums, extensions, typealiases, funcs,
subscripts and inits.

Still not handled correctly are associatedtypes.

rdar://problem/20582394
2017-07-31 09:57:00 -07:00
Alex Hoppen
ebd701c4b7 Represent the name of destructors by a special DeclBaseName
No longer use the known identifier `deinit` for destructors. This allows
classes to have functions called `deinit`.
2017-07-28 19:20:02 +02:00
Doug Gregor
1b2a2c9b90 [GSB/IRGen] Allow redundant inheritance of the JSExport protocol.
Inheritance of a protocol from JavaScriptCore's JSExport protocol is
used to indicate that the methods and properties of that protocol
should be exported to JavaScript. The actual check to determine
whether a protocol (directly) inherits JSExport is performed via the
Objective-C runtime. Note that the presence of JSExport in the
protocol hierarchy is not sufficient; the protocol must directly
inherit JSExport.

Swift warns about redundant conformance requirements and eliminates
them from the requirement signature (and, therefore, the Objective-C
metadata). This behavior is incorrect for JSExport, because the
conformance is actually needed for this API to work properly.

Recognize a protocol's inheritance JSExport specifically (by
name) when computing the requirement signature of the protocol. When
we find such a redundancy, suppress the "redundant conformance
constraint" diagnostic and add a new (hidden) attribute
@_restatedObjCConformance(proto). The attribute is used only by Objective-C
protocol metadata emission to ensure that we get the expected metadata
in the Objective-C runtime.

Fixes rdar://problem/32674145.
2017-07-24 17:02:34 -07:00
Robert Widmann
b77f2c147c Parse Shared
Add parser support for __shared and __owned as type attributes.  Also, extend parser diagnostics and tests to account for the new type attributes.
2017-07-23 21:47:25 -07:00
Jordan Rose
b4759bc8e2 [Parse] Split ParseSIL out into its own library.
...finally breaking the dependency of Parse on Sema.

There are still some unfortunate dependencies here -- Xi's working on
getting /AST/ not dependent on Sema -- but this is a step forward.

It is a little strange that parseIntoSourceFile is in ParseSIL, and
therefore that that's still a dependency for anyone trying to, well,
parse. However, nearly all clients that parse want to type-check as
well, and that requires Sema, Serialization, and the ClangImporter...
and Serialization and SIL currently require each other as well
(another circular dependency). So it's not actively causing us trouble
right now.
2017-07-17 12:18:41 -06:00
Jordan Rose
46d994fba8 [Parse] Sink all SIL parsing into SILParserTUState.
...in preparation for extracting SIL parsing into its own library.
2017-07-17 12:18:41 -06:00
Huon Wilson
2e952d2686 Merge pull request #10908 from huonw/swift3-is-behind-us-now
Upgrade some deprecation warnings from Swift 3 to errors in Swift 4.
2017-07-12 16:25:46 -07:00
Huon Wilson
55e1aa2a9f [Parse] Upgrade @noescape/@autoclosure(escaping) warnings to Swift 4 errors.
Part of rdar://problem/28961650 .
2017-07-12 13:26:09 -07:00
Huon Wilson
09f45c8f2b [Parse] Upgrade deprecated_operator_body* to Swift 4 errors.
Part of rdar://problem/28961650 .
2017-07-12 13:17:40 -07:00
Huon Wilson
e2d01f5cce [Parse] Upgrade operator_static_in_protocol to Swift 4 error.
Part of rdar://problem/28961650 .
2017-07-12 13:17:40 -07:00
Alex Hoppen
f8c2692f79 Introduce special decl names
Special DeclNames represent names that do not have an identifier in the
surface language. This implies serializing the information about whether
a name is special together with its identifier (if it is not special)
in both the module file and the swift lookup table.
2017-07-11 19:04:13 +02:00
Robert Widmann
82b13d11ac Merge pull request #10784 from CodaFi/my-sweet-noescape
[SR-5296] @autoclosure and @noescape are not decl attributes
2017-07-06 00:01:21 -07:00
Robert Widmann
ab580a3a0a Remove @autoclosure and @noescape as decl attributes
Using these in declaration position has been deprecated and
removed in Swift 3.  These attributes were not being parsed and
contained deadweight diagnostics that should have been moved
when these attributes became type attributes.
2017-07-05 21:27:04 -07:00
Robert Widmann
f11779572c Replace setLet with setSpecifier 2017-07-05 14:41:59 -07:00
Robert Widmann
4da853e7cb Rename Specifier::None to Specifier::Owned 2017-07-05 14:02:26 -07:00
Robert Widmann
ac5594dabe Use a meaningful representation of parameter specifiers
In anticipation of future attributes, and perhaps the ability to
declare lvalues with specifiers other than 'let' and 'var', expand
the "isLet" bit into a more general "specifier" field.
2017-06-29 16:03:49 -07:00
Huon Wilson
18078c104e Merge pull request #10476 from huonw/cleanups
Small clean-ups
2017-06-22 14:30:46 -07:00
Rintaro Ishizaki
e8cc8b55d8 [Parse] Fix #sourceLocation parsing in Decl position (#10444)
Fixes: https://bugs.swift.org/browse/SR-5242
`#sourceLocation` directive at end of declaration list postion was
rejected.
2017-06-22 12:35:43 +09:00
Huon Wilson
a4521c642b [NFC] Remove unnecessary radar reference. 2017-06-21 13:59:42 -07:00
Huon Wilson
61606a6616 [Parse] Provide better diagnostics for func 1() {}.
It is apparently a common mistake for beginners to start the names of functions
etc. with numbers, and before this patch the diagnostic wasn't specific about
the problem. It seems likely that most instances of `func 1(...` will be
mistakes in this vein, so this patch specifically diagnoses that case, and also
parses the number as the identifier to avoid follow on errors about top-level
closures (from the {}) and other invalid syntax.

Fixes rdar://problem/32316666 .
2017-06-20 16:49:50 -07:00
Jordan Rose
77de3dc1f2 [AST] Bring 'mutating' and 'inout self' in sync. (#10375)
- A mutating method or accessor always has 'inout self'.
- A nonmutating method or accessor never has 'inout self'.
- Only instance members can be mutating.
- Addressors are still addressors even when on static members.

Came up after reviewing another patch that confused the two as
possibly distinct concepts.
2017-06-19 16:16:47 -07:00
Slava Pestov
732b215b88 Merge pull request #9413 from rintaro/ast-eliminate-ifconfigstmt
[AST] Eliminate IfConfigStmt
2017-06-16 15:39:47 -07:00
Jordan Rose
5c1967397b Update and re-enable the diagnostics for unstable runtime names.
This time, the warnings only fire when the class in question directly
conforms to NSCoding. This avoids warning on cases where the user has
subclassed something like, oh, UIViewController, and has no intention
of writing it to a persistent file.

This also removes the warning for generic classes that conform to
NSCoding, for simplicity's sake. That means
'@NSKeyedArchiverEncodeNonGenericSubclassesOnly' is also being
removed.

Actually archiving a class with an unstable mangled name is still
considered problematic, but the compiler shouldn't emit diagnostics
unless it can be sure they are relevant.

rdar://problem/32314195
2017-06-05 17:32:26 -07:00
Jordan Rose
f0aca936c7 Allow '@objc(RuntimeName)' on classes with generic ancestry.
This is accomplished by recognizing this specific situation and
replacing the 'objc' attribute with a hidden '_objcRuntimeName'
attribute. This /only/ applies to classes that are themselves
non-generic (including any enclosing generic context) but that have
generic ancestry, and thus cannot be exposed directly to Objective-C.

This commit also eliminates '@NSKeyedArchiverClassName'. It was
decided that the distinction between '@NSKeyedArchiverClassName' and
'@objc' was too subtle to be worth explaining to developers, and that
any case where you'd use '@NSKeyedArchiverClassName' was already a
place where the ObjC name wasn't visible at compile time.

This commit does not update diagnostics to reflect this change; we're
going to change them anyway.

rdar://problem/32414557
2017-06-05 17:32:25 -07:00
Alex Hoppen
de5000f9a6 [Parser] Preparations for removal of getName on ValueDecl
With the introduction of special decl names, `Identifier getName()` on
`ValueDecl` will be removed and pushed down to nominal declarations
whose name is guaranteed not to be special. Prepare for this by calling
to `DeclBaseName getBaseName()` instead where appropriate.
2017-05-28 19:13:24 -07:00
Rintaro Ishizaki
c8d717e5f4 [Parse] Cleanup #if directive parsing
Now that, IfConfigDecl holds ASTNode regardless statements position or
declarations postion. We can construct it in single method.
2017-05-16 20:52:46 +09:00
Rintaro Ishizaki
6fa84150c5 [AST] Eliminate IfConfigStmt
Resolves: https://bugs.swift.org/browse/SR-4426

* Make IfConfigDecl be able to hold ASTNodes
* Parse #if as IfConfigDecl
* Stop enclosing toplevel #if into TopLevelCodeDecl.
* Eliminate IfConfigStmt
2017-05-16 12:19:54 +09:00
Rintaro Ishizaki
f1b0285bbc [Parse] Don't Hoist IfConfig{Decl,Stmt} out of IfConfig{Decl,Stmt} 2017-05-16 12:09:56 +09:00
Doug Gregor
7955aa13e6 Rename @NSKeyedArchive* attributes.
@NSKeyedArchiveLegacy -> @NSKeyedArchiverClassName
@NSKeyedArchiveSubclassesOnly -> @NSKeyedArchiverEncodeNonGenericSubclassesOnly

Fixes rdar://problem/32178796.
2017-05-15 11:02:31 -07:00
Huon Wilson
aadb959143 [Parse] Delete incorrect comment. NFC. 2017-05-11 17:01:55 +10:00
practicalswift
492f5cd35a [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar)
Replace `NameOfType foo = dyn_cast<NameOfType>(bar)` with DRY version `auto foo = dyn_cast<NameOfType>(bar)`.

The DRY auto version is by far the dominant form already used in the repo, so this PR merely brings the exceptional cases (redundant repetition form) in line with the dominant form (auto form).

See the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es11-use-auto-to-avoid-redundant-repetition-of-type-names) for a general discussion on why to use `auto` to avoid redundant repetition of type names.
2017-05-05 09:45:53 +02:00