Commit Graph

723 Commits

Author SHA1 Message Date
David Farler
414cfe7487 Minor changes to keyword-as-identifier diagnostics
- Remove stray newline
- Adjust wording when recommending backticks for a keyword identifier
- Provide fix-it when encountering a keyword as an identifier

rdar://problem/25761380
2016-05-10 14:49:21 -07:00
David Farler
b4dbdc49c2 Provide a more specific diag when using keywords as identifiers
When declaring a function like func repeat(){}, the diagnostic is
"expected an identifier" but 'repeat' looks like a reasonable
identifier at first glance, so actually say why it isn't.

rdar://problem/25761380
2016-05-10 11:08:13 -07:00
Jordan Rose
d7b3b6a462 Validate the "renamed" argument to @available.
It should have the same form as the argument to NS_SWIFT_NAME
in Objective-C, except that it permits operators and (currently)
disallows instance members and properties. We do get to share the
same parsing code, at least.

This actually caught an error in the Foundation overlay!

Groundwork for SR-1008.
2016-04-28 20:21:30 -07:00
Chris Lattner
4992474168 Add support for #sourceLocation in its ratified forms. Switch gyb to produce
the new form.  This keeps accepting #setline for now, but we should rip it out
at some point.
2016-03-11 22:21:42 -08:00
practicalswift
35dbeef034 [gardening] Fix recently introduced typos
* currnet → current
* accidental double space ("  ") → intentional single space (" ")
* recordinf → recording
2016-03-02 22:25:46 +01:00
Doug Gregor
3ffbe020d7 [Clang importer] Handle name mapping for "getter:" and "setter:" in swift_name.
The swift_name string format now supports "getter:" and "setter:"
prefixes to indicate that a function is the getter or setter of a
Swift-synthesized property. Start parsing these DeclNames and make
sure they're reflected in the Swift name lookup tables.

[Clang update required]
2016-03-01 15:33:21 -08:00
Doug Gregor
7265328e07 [Clang importer] Generalize name lookup tables for globals-as-members.
A swift_name attribute on a global declaration can specify a dotted
name (e.g., SomeStruct.member) to map that global into a member of the
(Swift-)named type. Handle this mapping in DeclName parsing, plumb it
through importFullName, and cope with it in the Swift name lookup
tables (tested via the dump) and importing into a Swift DeclContext
(as-yet-untested). Part of SE-0033.
2016-03-01 15:33:20 -08:00
Jordan Rose
6272941c5c Rename "build configurations" to "conditional compilation blocks".
...because "build configuration" is already the name of an Xcode feature.

- '#if' et al are "conditional compilation directives".
- The condition is a "conditional compilation expression", or just
  "condition" if it's obvious.
- The predicates are "platform conditions" (including 'swift(>=...)')
- The options set with -D are "custom conditional compilation flags".
  (Thanks, Kevin!)

I left "IfConfigDecl" as is, as well as SourceKit's various "BuildConfig"
settings because some of them are part of the SourceKit request format.
We can change these in follow-up commits, or not.

rdar://problem/19812930
2016-02-12 11:09:26 -08:00
Daniel Duan
6498c163eb [Parser][SR-698][Qol] add diagnostic for trailing ',' in lists
https://bugs.swift.org/browse/SR-698
2016-02-10 19:18:59 -08:00
Chris Lattner
8dedfb31e3 Add support for #file/#line, etc according to SE-0028. __FILE__ and friends
are still accepted without deprecation warning as of this patch.
2016-02-04 14:22:22 -08:00
Chris Lattner
7c97117d77 Fix IDE crashers 027, 066, and 068.
Expand the "skip" functions in the parser to be more careful about
not skipping passed a #endif or a code completion token, since they
are synchronization points for the parser.

The fix was to change Parser::delayParseFromBeginningToHere to use
a manual loop instead of skipUntil (which can stop early for non-EOF
tokens).
2016-02-01 16:36:28 -08:00
Denis Vnukov
42cba88f2c Properly handle tokens split in parser inside swift::tokenize(...)
Swift parser splits tokens in few cases, but it swift::tokenize(...) does not know
about that. In order to reconstruct token stream as it was seen by the parser,
we need to collect the tokens it decided to split and use this information
in swift::tokenize(...).
2016-01-27 13:43:39 -08:00
practicalswift
6d0eee9b8c Remove unused variables. 2016-01-21 10:33:17 +01:00
Doug Gregor
4ce77cb39f Deserialize swift3_migration attribute with an empty "renamed" string. 2016-01-14 16:37:25 -08:00
Doug Gregor
67c81154af Add a swift3_migration attribute to describe how an API gets migrated.
Introduce a new attribute, swift3_migration, that lets us describe the
transformation required to map a Swift 2.x API into its Swift 3
equivalent. The only transformation understood now is "renamed" (to
some other declaration name), but there's a message field where we can
record information about other changes. The attribute can grow
somewhat (e.g., to represent parameter reordering) as we need it.

Right now, we do nothing but store and validate this attribute.
2016-01-13 16:53:01 -08:00
Chris Lattner
2f4bec9e8c subsume the "startsWithGreater" logic into skipUntilGreaterInTypeList, and make sure skipUntilGreaterInTypeList return a valid location even in the case of parse errors. This ensures that we form a valid source range. Also, improve parseExprIdentifier() to handle the case when skipUntilGreaterInTypeList returns an empty archetype argument list. This fixes a couple of compiler crashers. 2016-01-09 20:36:05 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Chris Lattner
886b647396 fix <rdar://21712891> Swift Compiler bug: String subscripts with range should require closing bracket.
This is a parser bug causing us to accept invalid code.
2015-12-22 21:25:51 -08:00
Doug Gregor
c8dd8d0661 Implement SE-0001: Allow (most) keywords as argument labels.
Allow all keywords except for parameter introducers (var/let/inout) to
be argument labels when declaring or calling a
function/initializer/subscript, e.g., this

  func touchesMatching(phase: NSTouchPhase, `in` view: NSView?) -> Set<NSTouch>

can now be expressed as

  func touchesMatching(phase: NSTouchPhase, in view: NSView?) -> Set<NSTouch>

and the call goes from

  event.touchesMatching(phase, `in`: view)

to

  event.touchesMatching(phase, in: view)

Fixes [SR-344](https://bugs.swift.org/browse/SR-344) /
rdar://problem/22415674.
2015-12-22 16:18:28 -08:00
Jordan Rose
c40e8d9031 Add frontend option -debug-time-compilation.
This times each phase of compilation, so you can see where time is being
spent. This doesn't cover all of compilation, but does get all the major
work being done.

Note that these times are non-overlapping, and should stay that way.
If we add more timers, they should go in a different timer group, so we
don't end up double-counting.

Based on a patch by @cwillmor---thanks, Chris!

Example output, from an -Onone build using a debug compiler:

===-------------------------------------------------------------------------===
                               Swift compilation
===-------------------------------------------------------------------------===
  Total Execution Time: 8.7215 seconds (8.7779 wall clock)

   ---User Time---   --System Time--   --User+System--   ---Wall Time---  --- Name ---
   2.6670 ( 30.8%)   0.0180 ( 25.3%)   2.6850 ( 30.8%)   2.7064 ( 30.8%)  Type checking / Semantic analysis
   1.9381 ( 22.4%)   0.0034 (  4.8%)   1.9415 ( 22.3%)   1.9422 ( 22.1%)  AST verification
   1.0746 ( 12.4%)   0.0089 ( 12.5%)   1.0834 ( 12.4%)   1.0837 ( 12.3%)  SILGen
   0.8468 (  9.8%)   0.0171 ( 24.0%)   0.8638 (  9.9%)   0.8885 ( 10.1%)  IRGen
   0.6595 (  7.6%)   0.0142 ( 20.0%)   0.6737 (  7.7%)   0.6739 (  7.7%)  LLVM output
   0.6449 (  7.5%)   0.0019 (  2.6%)   0.6468 (  7.4%)   0.6469 (  7.4%)  SIL verification (pre-optimization)
   0.3505 (  4.1%)   0.0023 (  3.2%)   0.3528 (  4.0%)   0.3530 (  4.0%)  SIL optimization
   0.2632 (  3.0%)   0.0005 (  0.7%)   0.2637 (  3.0%)   0.2639 (  3.0%)  SIL verification (post-optimization)
   0.0718 (  0.8%)   0.0021 (  3.0%)   0.0739 (  0.8%)   0.0804 (  0.9%)  Parsing
   0.0618 (  0.7%)   0.0010 (  1.4%)   0.0628 (  0.7%)   0.0628 (  0.7%)  LLVM optimization
   0.0484 (  0.6%)   0.0011 (  1.5%)   0.0495 (  0.6%)   0.0495 (  0.6%)  Serialization (swiftmodule)
   0.0240 (  0.3%)   0.0006 (  0.9%)   0.0246 (  0.3%)   0.0267 (  0.3%)  Serialization (swiftdoc)
   0.0000 (  0.0%)   0.0000 (  0.0%)   0.0000 (  0.0%)   0.0000 (  0.0%)  Name binding
   8.6505 (100.0%)   0.0710 (100.0%)   8.7215 (100.0%)   8.7779 (100.0%)  Total
2015-12-17 15:19:09 -08:00
practicalswift
b56beef1c3 Fix typo: charater → character 2015-12-14 00:11:22 +01:00
practicalswift
c9482d5fd1 Fix typo: caracter → character 2015-12-14 00:11:22 +01:00
David Farler
9d373d0fc7 Add _compiler_version build configuration
This configuration clause will suppress lex diagnostics and skip parsing
altogether if the code under the clause isn't active - the compiler must
have a repository version greater than or equal to the version given to
_compiler_version.

This option is only meant to be used sparingly and not to track the
Swift *language* version.

Example, if using a compiler versioned 700.0.28:

  #if _compiler_version("700.0.23")
    print("This code will compile for versions 700.0.23 and later.")
  #else
    This + code + will + not + be + parsed
  #endif

Included are new diagnostics for checking that the version is formatted
correctly and isn't empty.

New tests:
- Compiler version comparison unit tests
- Build configuration diagnostics
- Skipping parsing of code under inactive clauses

rdar://problem/22730282

Swift SVN r32195
2015-09-24 02:14:47 +00:00
Xi Ge
4dcc3f1469 [CodeCompletion] No crash on a terribly wrong code completion position. rdar://21796881
Swift SVN r30706
2015-07-28 00:02:33 +00:00
Jordan Rose
fbb8d3f9a8 Add "interface hash" for improved incremental builds.
Compute the hash of all interface tokens when parsing; write the
interface hash to the swiftdeps file, or if the -dump-interface-hash
option is passed to the frontend. This hash will be used in incremental
mode to determine whether a file's interface has changed, and therefore
whether dependent files need to be rebuilt in response to the change.

Committed on ChrisW's behalf while he gets his setup unborked.

rdar://problem/15352929

Swift SVN r30477
2015-07-22 00:13:54 +00:00
Slava Pestov
4e26069c8f Parse: Fix EndLoc of #if without #endif in parseDeclIfConfig(), and clean up duplication
Fixes <rdar://problem/19671208>.

Swift SVN r30314
2015-07-17 08:31:21 +00:00
Slava Pestov
c1b3569192 Parse: Fix crash with invalid protocol compositions, and improve error recovery
Fixes <rdar://problem/19686707>.

Swift SVN r30304
2015-07-17 05:57:22 +00:00
Chris Lattner
da4ea30b23 Make the parser handle #if directives better when skipping due to error recovery. Previously,
we would blow past a #endif directive, which leads to bad things later.

this will be tested in a forthcoming testcase.


Swift SVN r29915
2015-07-06 05:28:55 +00:00
Chris Lattner
ec95a37e08 rework the disambiguation logic that determines whether a token stream is
likely to be a c-style for loop or a for-each loop.  NFC except in one recovery
cases where we already spray crazy diagnostics.


Swift SVN r28023
2015-05-01 04:42:56 +00:00
John McCall
3d3f1a7d7e Parsing/AST/Sema support for rethrows, and fix bugs with
throws/rethrows override and conformance checking.

Swift SVN r27508
2015-04-20 23:39:12 +00:00
Jordan Rose
613b194025 [IDE] Honer @testable for top-level completions as well.
This is the last planned Swift-side fix for testability in this release!

rdar://problem/17732115

Swift SVN r26949
2015-04-03 20:20:17 +00:00
Joe Pamer
eee40fc53f Add basic parsing, sema and mangling support for throwing function types. Next up, metadata and serialization support, as well as more tests.
Swift SVN r26767
2015-03-31 18:55:19 +00:00
Chris Lattner
3e3f568179 By far, the most common use of Lexer::getLocForEndOfToken is in
conjunction with .fixItInsert().  As such, introduce a helper named
.fixItInsertAfter() that does what we all want.  Adopt this in various
places around the compiler.  NFC.



Swift SVN r26147
2015-03-15 05:30:04 +00:00
Denis Vnukov
59c30abfd4 Minor: coding style fix
Swift SVN r23516
2014-11-21 17:00:29 +00:00
Denis Vnukov
ca208dfc8c Extending ParserUnit to optionally accept LangOptions and module name.
Needed by fix in SourceKit which will be submitted later (rdar://problem/18945845, 
SourceKit crashed in SourceKit::SwiftEditorDocument::replaceText()).



Swift SVN r23511
2014-11-21 16:38:18 +00:00
Denis Vnukov
b23dc5c61b Minor fix in implicitly unwrapped optional suffix parsing (rdar://problem/18634543)
Swift SVN r22858
2014-10-21 16:28:57 +00:00
Joe Groff
e102c521cc Improve parsing of '>>?!>?' jumbles in type context.
Use the same token-splitting technique we use to interpret '>>>' as a series of closing angle brackets to also extract '?' and '!' IUO sigils. Tweak it so that we properly reset the lexer state instead of just peeking the next token, because otherwise, when we chop a token like '>?>>', we'll see only the '?' (because '?' by itself is a question_postfix) and drop the '>>' on the floor. Remove the lexer hacks that pattern-matched specific >?>? sequences.

Swift SVN r22669
2014-10-10 17:41:03 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
Jordan Rose
29f8c25d63 Move #line state into the Parser and out of the SourceManager.
As part of this change, allow #line directives to extend to the end of the
file, rather than requiring a reset.

Note that #line regions that start or end within function bodies will not
behave correctly when in delayed parsing modes. This was true before and
after this commit. (#line regions contained entirely within a function and
not within any other #line regions should be fine.)

Swift SVN r20571
2014-07-25 23:01:43 +00:00
Argyrios Kyrtzidis
8eb7d43d32 [Parser] Introduce a convenience wrapper for Parser functionality.
This is useful when wanting to just do some syntactic parsing for a snippet of code.

Swift SVN r20174
2014-07-18 19:57:32 +00:00
Adrian Prantl
400f1774e9 Add support for a #line directive.
This patch extends the syntax with a new #line directive that is inspired
by the homonymous CPP directive. It can be specified in all locations a #if
is legal (Stmt, Decl).

Semantics
---------

#line 42 "file.swift"
This makes diagnostics and debug information behave as if the subsequent
lines came from file.swift+42.

#line // without arguments
This switches back to the main source file and the switches back to the
normal line numbering. Any previous #line directives will result in gaps
in the main file.

Rationale
---------

LLDB and the REPL need this for making expressions that are entered into
the expression evaluator or REPL debugable. For more info see
<rdar://problem/17441710> Need #line directive or something similar so we can enhance the debugging of expressions and REPL

Also, I believe the stdlib would benefit from this and it would allow us
to get rid of the line-directive wrapper script.

Swift SVN r19384
2014-06-30 23:50:11 +00:00
Argyrios Kyrtzidis
ca8c683810 [Parser] When failing to match the token in Parser::parseMatchingToken, return the previous source location.
Fixes SourceKit test.

Swift SVN r19319
2014-06-28 03:16:40 +00:00
Doug Gregor
461cde049a Teach parseMatchingToken() to set a matched location even when it wasn't matched.
We were working around this in several different places, which was
error-prone (see <rdar://problem/17479771>). This way, we always have
usable left/right delimiter locations.

Swift SVN r19292
2014-06-27 15:17:05 +00:00
Jordan Rose
574054b8fd Distance SourceManager from llvm::SourceMgr.
...in preparation for non-source locations, i.e. locations that don't come
frome source buffers.

No functionality change, but a fair bit of SourceManager API and idioms have
changed.

Swift SVN r18942
2014-06-17 01:15:47 +00:00
Chris Lattner
92af326a15 generalize consumeIdentifier to work with self and Self. Use it in a few
more places to simplify code.  NFC.


Swift SVN r17438
2014-05-05 14:48:56 +00:00
Chris Lattner
0c390777ba Implement <rdar://problem/16204675> Need #elseif
This restructures IfConfigDecl/Stmt to be a list of clauses controlled
by a condition.  This makes it straight-forward to drop in #elseif support.

While I'm in here, this patch moves checking for extraneous stuff at the
end of the #if line from the lexer to the parser.  This means that you can
now put a comment on the same line as a #if/#else/#elseif/#endif.



Swift SVN r16912
2014-04-27 04:51:36 +00:00
Doug Gregor
57b2146c0b Remove the separated call syntax.
We had our transition path, and now it's time to kill it because it's
causing problems <rdar://problem/16672558>.

Amusing note: the SILGen test change is actually an improvement. We
weren't rebinding self when performing initializer delegation with the
separated call syntax.

Swift SVN r16707
2014-04-23 18:20:34 +00:00
Chris Lattner
b204be71cd simplify Parser::isStartOfStmt: just use the current token instead of having
all of the clients pass in the current token.  NFC.


Swift SVN r16601
2014-04-21 04:01:03 +00:00
Manman Ren
1b8087cf5d [SILParser] Handle overloaded members for protocol_method and dynamic_method.
We print the AST type for the member when printing SILDeclRef for
protocol_method and dynamic_method. The AST type can be polymorphic, so parsing
of PolymorphicFunctionType is added to the Parser. Also add parsing "inout"
right before an identifier type. "inout" was parsed only in parseTypeTupleBody.

rdar://15763213


Swift SVN r16460
2014-04-17 17:56:57 +00:00
Dmitri Hrybenko
f90e0c153b Make 'override' a keyword
rdar://16462192

Swift SVN r16115
2014-04-09 14:19:50 +00:00