Commit Graph

567 Commits

Author SHA1 Message Date
Jordan Rose
8d7f1b7c5d [AST] Separate SourceFile from FileUnit.h
Like the last commit, SourceFile is used a lot by Parse and Sema, but
less so by the ClangImporter and (de)Serialization. Split it out to
cut down on recompilation times when something changes.

This commit does /not/ split the implementation of SourceFile out of
Module.cpp, which is where most of it lives. That might also be a
reasonable change, but the reason I was reluctant to is because a
number of SourceFile members correspond to the entry points in
ModuleDecl. Someone else can pick this up later if they decide it's a
good idea.

No functionality change.
2019-09-17 17:54:41 -07:00
Jordan Rose
853caa66d4 [AST] Split FileUnit and its subclasses out of Module.h
Most of AST, Parse, and Sema deal with FileUnits regularly, but SIL
and IRGen certainly don't. Split FileUnit out into its own header to
cut down on recompilation times when something changes.

No functionality change.
2019-09-17 17:54:41 -07:00
Rintaro Ishizaki
9f642f0bc1 Revert "Merge pull request #27203 from CodaFi/movin-on-up"
This reverts commit 387d2a9aee, reversing
changes made to bf1ab6c29d.
2019-09-17 16:42:44 -07:00
Robert Widmann
d8aaf29617 Revert "Merge pull request #27132 from rintaro/syntaxparse-parsedrawsyntax-moveonly"
This reverts commit e675c4947d, reversing
changes made to 73315ba01e.
2019-09-16 15:10:33 -07:00
Rintaro Ishizaki
80085e0d27 [SyntaxParse] Make ParsedRawSyntaxNode move-only
So that we can easily detect 'ParsedSyntaxNode' leaking. When it's
moved, the original node become "null" node. In the destructor of
'ParsedSyntaxNode', assert the node is not "recorded" node.
2019-09-11 16:33:49 -07:00
Jan Svoboda
f0395a469a Revert "Revert "[Parser] Decouple the parser from AST creation (part 1)"" 2019-07-30 04:34:09 +00:00
Slava Pestov
a532a325e1 AST: Move a few methods from VarDecl down to ParamDecl 2019-07-22 20:19:09 -04:00
Victor Guerra
2cfe8ad52a Addressing feedback on how parseDefaultArgument should consume '=' or '==' 2019-07-16 22:32:19 +02:00
Victor Guerra
d82dd84592 Moving check for '==' close to that of '=' and diagnose there.
As well, parser recovers from usage of '==' and parses the whole
parameter clause.
2019-07-16 13:20:36 +02:00
Victor Guerra
3b1e881285 [Diagnostics] Improve diagnostic when using == instead of = for default function argument. 2019-07-14 14:30:17 +02:00
Rintaro Ishizaki
04ca9752cf [CodeCompletion] Enable type name completion for param decl attribute
rdar://problem/50074177
2019-06-11 17:34:45 -07:00
Rintaro Ishizaki
b31c142efb [CodeCompletion] Implement completion at custom attribute argument 2019-06-11 17:34:44 -07:00
Rintaro Ishizaki
62193c961e [CodeCompletion] Enable type completion at beginning of attribute
for 'VarDecl' or if we don't know the kind of the decl.
Property delegate allows arbitrary type name (with `@propertyDelegate`
attr).
2019-06-11 17:34:44 -07:00
Rintaro Ishizaki
9ba232d718 [CodeCompletion] Implement completion at custom attribute argument 2019-05-31 11:09:54 -07:00
Rintaro Ishizaki
878c9c600b [CodeCompletion] Enable type completion at beginning of attribute
for 'VarDecl' or if we don't know the kind of the decl.
Property delegate allows arbitrary type name (with `@propertyDelegate`
attr).
2019-05-31 09:44:19 -07:00
Sam Lazarus
3d9b6396a1 Merge pull request #24059 from sl/sl/sr-10293
Allow var / let as parameter names but provide a warning and fixit to add backticks.
2019-04-26 09:30:23 -04:00
Sam Lazarus
2a38b48eea Parse / AST: Allow let / var as argument labels with a warning.
The diagnostic is now a warning and the new message alerts the user that
though it is valid to have let and var as argument label names,
they are interpreted as argument labels, not keywords.
2019-04-26 04:08:01 -04:00
Rintaro Ishizaki
7078862921 [CodeCompletion] Provide 'some' keyword where applicable
rdar://problem/49353647
2019-04-19 17:11:16 -07:00
Nathan Hawes
d4f1894347 Simplify diagnostics for inherited default argument values in module interfaces
Also:
- additionally require the containing and overridden initializers are
  designated, as that's the only case in which we should produce the '= super'
  syntax in module interfaces
- Add notes to point out the locations of the overriden initializer when it's
  not designated, and the corresponding parameter in that initializer when it
  doesn't have a default argument to inherit.
2019-04-18 11:03:34 -07:00
Nathan Hawes
c95252e1e5 Change from using the @_inheritedDefaultValue attribute to mark parameters with an inherited default argument to using '= super' 2019-04-16 15:21:25 -07:00
Nathan Hawes
9639bceded Add an attribute to inhert a param's default value from the overridden decl in module interfaces 2019-04-16 11:22:36 -07:00
Slava Pestov
6bb36b5c01 Sema: Subscript default arguments
Fixes <https://bugs.swift.org/browse/SR-6118>.
2019-04-02 20:37:01 -04:00
Robert Widmann
944d8d06d7 [SE-0155] Default Arguments in Enum Cases
The bulk of the changes are to SILGenApply.  As we must now evaluate the
payload ArgumentSource to an RValue, we follow the example of subscripts
and lie to the argument emitter.  This evaluates arguments at +1 which
can lead to slightly worse codegen at -Onone.
2019-02-12 10:06:48 -05:00
Rintaro Ishizaki
6aee036812 Merge pull request #22214 from bannzai/syntax/add/function/make_ellipsis_token
[SwiftSyntax] Add SyntaxFactory.makeEllipsisToken function.
2019-02-11 16:27:37 -08:00
bannzai
75d24cb65a Setting ellipsis token kind 2019-02-07 23:16:18 +09:00
Pavel Yaskevich
9da67c1897 [TypeChecker] Drop @autoclosure attribute from invalid parameters
While forming/validating parameters make sure that the type is indeed
a function type before marking it as `autoclosure` based on type
representative attributes, because parser doesn't change attributes
even after the error has been found and diagnosed.

Resolves: rdar://problem/47586626
2019-01-28 17:01:05 -08:00
Argyrios Kyrtzidis
ab7427723e [Parse/Syntax] Refactoring to decouple the parser from syntax tree creation
Instead of creating syntax nodes directly, modify the parser to invoke an abstract interface 'SyntaxParseActions' while it is parsing the source code.
This decouples the act of parsing from the act of forming a syntax tree representation.
'SyntaxTreeCreator' is an implementation of SyntaxParseActions that handles the logic of creating a syntax tree.
To enforce the layering separation of parsing and syntax tree creation, a static library swiftSyntaxParse is introduced to compose the two.

This decoupling is important for introducing a syntax parser library for SwiftSyntax to directly access parsing.
2019-01-07 19:52:59 -08:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
Pavel Yaskevich
ed84f18686 [AST] NFC: Remove a FIXME related to ParamDecl::IsAutoClosure field 2018-11-10 11:59:29 -08:00
Pavel Yaskevich
53417f4aba [AST] Propagate @autoclosure flag to parameter decl and type flags 2018-11-10 11:59:28 -08:00
Slava Pestov
3265bffa8f Parse: Remove the fixit for curried parameter lists, its wrong anyway
Fixes <rdar://problem/45274153>.
2018-10-30 14:02:35 -04:00
Rintaro Ishizaki
9df8b2f2a6 [CodeCompletion] Preserve completion status in 'let' pattern
Also, stop context type analysis at outer most expression that matches
the position. It seems that that produces more appropriate results.

rdar://problem/30103287
2018-10-30 19:14:03 +09:00
Christopher Ian Stern
469a0f3eb0 fix stack overflow on deeply nested parens [SR-4866] (#19631)
Make sure StructureMarkerRAII checks structure nesting level on all paths.  Previously swift crashed with  no diagnostic on deeply nested '('. Now we print an error when more than 256 parens deep, just as we always have for '['.

fixes SR-4866
2018-10-10 13:42:18 +09:00
Harlan
ad7e1d0e67 [InterfaceGen] Print private/internal properties (#19127)
* [Interface] Print private/internal properties

All properties which contribute to the storage of a type should be
printed, and their names should be hidden from interfaces. Print them
with '_' as their name, and teach the parser to recognize these special
patterns when parsing interface files.

Partially resolves rdar://43810647

* Address review comments

* Disable accessor generation for nameless vars

* Test to ensure interface files preserve type layout

* Ignore attribute differences on Linux
2018-09-06 09:58:33 -07:00
Harlan
dc1bc823e6 [InterfaceGen] Remove #ifs from default arguments (#19075)
* [InterfaceGen] Remove #ifs from default args

This patch removes all #if configs form the bodies of default arguments,
which can contain multiline closures, while preserving the bodies of the
clauses that are active.

This code is generalized and should "just work" for inlinable function
bodies, which will come in a later patch.

* Address review comments

* Fix and test CharSourceRange.overlaps

* Fix CharSourceRange::print to respect half-open ranges
2018-08-31 20:18:48 -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
Rintaro Ishizaki
682fc12c39 [Parse] Don't use getAsNominalTypeOrNominalTypeExtensionContext in Parse
`getAsNominalTypeOrNominalTypeExtensionContext()` requires fully parsed
AST. Use `isTypeContext()` instead.

https://bugs.swift.org/browse/SR-8554
rdar://problem/43394866
2018-08-18 12:48:13 +09:00
Jordan Rose
537954fb93 [AST] Rename several DeclContext methods to be clearer and shorter (#18798)
- getAsDeclOrDeclExtensionContext -> getAsDecl

This is basically the same as a dyn_cast, so it should use a 'getAs'
name like TypeBase does.

- getAsNominalTypeOrNominalTypeExtensionContext -> getSelfNominalTypeDecl
- getAsClassOrClassExtensionContext -> getSelfClassDecl
- getAsEnumOrEnumExtensionContext -> getSelfEnumDecl
- getAsStructOrStructExtensionContext -> getSelfStructDecl
- getAsProtocolOrProtocolExtensionContext -> getSelfProtocolDecl
- getAsTypeOrTypeExtensionContext -> getSelfTypeDecl (private)

These do /not/ return some form of 'this'; instead, they get the
extended types when 'this' is an extension. They started off life with
'is' names, which makes sense, but changed to this at some point.  The
names I went with match up with getSelfInterfaceType and
getSelfTypeInContext, even though strictly speaking they're closer to
what getDeclaredInterfaceType does. But it didn't seem right to claim
that an extension "declares" the ClassDecl here.

- getAsProtocolExtensionContext -> getExtendedProtocolDecl

Like the above, this didn't return the ExtensionDecl; it returned its
extended type.

This entire commit is a mechanical change: find-and-replace, followed
by manual reformatted but no code changes.
2018-08-17 14:05:24 -07:00
Rintaro Ishizaki
9f91899afd Merge pull request #18589 from rintaro/rdar43057057
[Parse] Set ErrorType to invalid ParamDecl
2018-08-14 07:58:12 +09:00
Rintaro Ishizaki
5e001f1913 Merge pull request #18626 from rintaro/ide-completion-unresolved-refactor
[CodeCompletion] Completion for UnresolvedMember via CodeCompletionExpr
2018-08-11 09:10:28 +09:00
Slava Pestov
4b258e86e6 AST: Stop setting contextual types on ParamDecls
VarDecl::getType() lazily maps the interface type into context if needed.
2018-08-10 13:33:12 -07:00
Rintaro Ishizaki
aac92da252 [CodeCompletion] Completion for UnresolvedMember via CodeCompletionExpr
Using dummy UnresolvedMemberExpr doesn't give us much benefit. Instead, use
CodeCompletionExpr which is type checked as type variable so can use
CodeCompletionTypeContextAnalyzer to infer context types.
This way, we can eliminate most of special logic for UnresolvedMember.

rdar://problem/39098974
2018-08-10 22:23:23 +09:00
Rintaro Ishizaki
254be25f4d Merge pull request #18564 from rintaro/ide-completion-contextanalysis
[CodeCompletion] Improve context type analysis
2018-08-10 10:53:44 +09:00
Jordan Rose
0e10f89964 Preserve default argument text through serialization (#18579)
This allows us to dump it in the generated interface, though it's
still not syntax-highlighted. This is necessary for textual module
interfaces, but it's also just a longstanding request for Xcode's
"Generated Interface" / "Jump to Definition" feature.

rdar://problem/18675831
2018-08-09 11:06:22 -07:00
Rintaro Ishizaki
18582d3406 [CodeCompletion] Handle ExprPattern in context type analysis
This improves type inference for code completion in argument position of
EnumElementPattern.
2018-08-09 19:49:25 +09:00
Rintaro Ishizaki
5217b68f08 [Parse] Set ErrorType to invalid ParamDecl
TypeChecker assumes invalid decl has valid type.

https://bugs.swift.org/browse/SR-8475
rdar://problem/43057057
2018-08-09 15:55:33 +09:00
Rintaro Ishizaki
5058ec9158 Merge pull request #17787 from rintaro/parse-miscdiag-drop3
[Parse] Drop Swift3 support for misc diagnostics
2018-07-25 19:36:24 +09:00
Slava Pestov
df9f7f979a Parse: Remove uses of getParameterLists() from default argument parsing 2018-07-22 20:56:56 -07:00
Slava Pestov
bfc4121971 AST: Rework AbstractFunctionDecl construction away from multiple parameter lists
There are two general constructor forms here:

- One took the number of parameter lists, to be filled in later.
  Now, this takes a boolean indicating if there is an implicit
  'self'.

- The other one took the actual parameter lists and filled them
  in right away. This now takes a separate 'self' ParamDecl and
  ParameterList.

Instead of storing the number of parameter lists, an
AbstractFunctionDecl now only needs to store if there is a 'self'
or not.

I've updated most places that construct AbstractFunctionDecls to
properly use these new forms. In the ClangImporter, there is
more code that remains to be untangled, so we continue to build
multiple ParameterLists and unpack them into a ParamDecl and
ParameterList at the last minute.
2018-07-21 07:30:30 -07:00
Slava Pestov
8df02a96c9 Parse: Discard curried parameter lists
We still produce the same diagnostic as before, but don't add the
parameter lists to the function declaration at all. This allows us
to begin assuming that functions either have 1 or 2 parameter lists.
2018-07-19 12:28:26 -07:00