Commit Graph

105 Commits

Author SHA1 Message Date
Brent Royal-Gordon
d4ebd5df06 [NFC] Avoid violating same-filename rule in tests
…and modify resolveFileIDConflicts() to diagnose any such violations instead of asserting.

Swift does not allow any two files in the same module to have the same filename, even if they are in different directories. However, this is enforced in the driver, so tests that invoke the frontend directly can violate it. Turns out that a couple of those snuck into the test suite at various points.

This commit updates those tests. It also causes the frontend to diagnose the duplicate filename error just as the driver would have, which should help us understand what happened more easily if this crops up again in the future.

NFC, since invoking the frontend directly is unsupported.
2020-07-13 14:05:13 -07:00
Xi Ge
42cc989136 DependenciesScanner: teach the scanner to handle cross-import overlays 2020-06-09 10:38:52 -07:00
Robert Widmann
5dc060ee57 Define ResolveTypeRequest 2020-04-30 16:10:25 -07:00
Hamish Knight
7f8a0e8a6c Requestify implicit imports
Add ModuleImplicitImportsRequest, which computes
the modules that should be implicitly imported by
each file of a given module. Use this request in
import resolution to add all the necessary
implicit imports.

The request computes the implicit imports by
consulting the ImplicitImportInfo, which ModuleDecl
can now be created with. This allows us to remove
uses of `SourceFile::addImports` in favor of
adding modules needed to be implicitly imported to
the ImplicitImportInfo.
2020-04-20 13:20:35 -07:00
Owen Voorhees
fdb6eabb0a [Diagnostics] Move macros used in diagnostic definitions to their own header
These were duplicated in 11 different files, and as they've gotten more
complex a few inconsistencies have snuck in. Sharing them should make future
changes easier and less bug-prone.
2020-04-14 18:10:30 -07:00
Brent Royal-Gordon
d590823f3c Warn about conflicts between #file strings 2020-03-05 23:30:37 -08:00
Brent Royal-Gordon
747c50725c Add a warning about redundant cross-import declarations
These are mostly harmless, except that they make the two module names synonymous in qualified lookup. A hard error seems too aggressive for something that could easily be caused by uncoordinated changes to two modules, so warn instead.
2020-02-18 11:08:36 -08:00
Brent Royal-Gordon
e248f82773 Add support for loading cross-import files 2020-02-18 11:06:12 -08:00
Brent Royal-Gordon
addbe3e5ed [NFC] Thread DeclNameRef through most of the compiler
This huge commit contains as many of the mechanical changes as possible.
2019-12-11 00:55:18 -08:00
Owen Voorhees
f37c1dbaea [Gardening] Remove unused diagnostic definitions 2019-11-19 19:44:37 -08:00
Doug Gregor
190d96535c [Property wrappers] Fix source compatibility issue with attribute lookup.
Swift 5.1's lookup for custom attributes skipped associated type
members, which allowed code like the given example to compile. To
maintain source compatibility, identify the narrow case that happens
in practice---the property wrapper is at module scope but is now
shadowed by an associated type---warn about it, and accept it.

Fixes rdar://problem/56213175.
2019-10-11 22:44:50 -07:00
Owen Voorhees
68e6065c8e [Diagnostics][NFC] Introduce Structured fix-its
These are defined with macros like errors/warnings/notes, and
make use of format strings and diagnostic arguments. The intent
is to leverage diagnostic arguments in the future to disambiguate
ambiguously spelled types.

Ported a few miscellaneous fix-its to the new system
2019-09-05 10:43:25 -07:00
Holly Borla
71fb2629ac Sema: implement requiresClass using a request evaluator.
Add the request `ProtocolRequiresClassRequest` to lazily determine if a
`ProtocolDecl` requires conforming types to be a class.

Note that using the request evaluator to compute `requiresClass` introduces
cycle errors for protocol declarations, where this computation didn't
previously emit diagnostics. For now, we'll allow duplicate diagnostics in this
case, with the eventual goal of removing explicitly checking for cycles
via `checkCircularity` (instead letting the request evaluator handle cycle
diagnostics).
2019-07-17 16:04:24 -07:00
Xi Ge
5c22fd50e2 ABI checker: include all kinds of accessors for abstract storage decl and diagnose their missing.
Removing accessors other than getter and setter can be ABI breaking. This
patch starts to formally include all accessor decls in the tree and diagnose
their removal. This change only applies to the ABI checker since we still
exclude accessors other than getter and setter when diagnosing source
compatibility.

Including accessors formally can also allow us to check the missing
of availability attributes for newly added accessors.

rdar://52063421
2019-06-26 18:04:28 -07:00
Slava Pestov
24da27b179 AST: Verify that all generic signatures can be re-built from their requirements
-verify-generic-signatures didn't catch the bad case from
<https://bugs.swift.org/browse/SR-10752>. Add a new check and
make sure it now catches this kind of failure.
2019-06-14 16:00:37 -07:00
Brent Royal-Gordon
d9732a050f Allow the declaration of static subscripts
In this commit, MyStruct.self[0] parses and typechecks but the solution doesn’t apply correctly. MyStruct[0] gets diagnosed as an error.
2019-04-10 23:09:44 -07:00
Xi Ge
ecd1e84526 doc-serialization: diagnose missing group-info file or corrupted one.
rdar://45903094
2019-02-21 15:28:35 -08:00
Suyash Srijan
0d9f63474a [Sema] Emit a diagnostic when extending a protocol with a redundant requirement (#20503)
* Emit a warning diagnostic if an extension contains a redundant requirement

* Updates diagnostic message and checks if the extension type is a protocol

* Updates indentation and extracts self type

* [ast] Updates diagnostic message

* [ast] fix indentation

* [ast] Change ':' to 'to' in 'protocol_extension_redundant_requirement'

* [sema] Adds protocol extension redundant requirement check

Moved from TypeCheckRequests to TypeCheckGeneric

* [ast] fix some crashes related to null ptrs, check self type before emitting a diagnostic, update tests

* [ast] renames 'owner' to 'ext'

* [sema] fix style

* [test] Add another test case for redundant requirement

Co-Authored-By: theblixguy <suyashsrijan@outlook.com>

* [test] fix failing test

The test was failing because A has already been declared as a typealias.
2018-11-15 19:18:51 -08:00
Graydon Hoare
5a563f59af [Stats] Add SWIFTC_MAXIMUM_DETERMINISM to inhibit parallelism everywhere. 2018-09-13 16:15:49 -07:00
Brent Royal-Gordon
004ada98bc Add errors for other invalid strings in digester
Specifically, TypeAttrKinds, DeclAttrKinds, and DeclKinds.
2018-08-17 04:16:20 -07:00
Brent Royal-Gordon
88ac6f11a2 Add error for invalid SDKNodeKind 2018-08-17 00:27:38 -07:00
Brent Royal-Gordon
ec87277e56 Add error for unknown API KeyKind 2018-08-16 23:52:06 -07:00
Doug Gregor
9e95a93125 [Evaluator] Sink type checker requests into the AST library.
Sink the type checker request classes into the AST library, so that
various functions in the AST library can form type-checking requests.
The actual evaluator functions for these requests continue to live
in the Sema library, called via indirection through the function
pointer tables registered with the request-evaluator.
2018-06-29 15:58:57 -07:00
Robert Widmann
1beb75583a Push FunctionTypeRepr Input Invariants Up
Validation of the input side of FunctionTypeRepr was previously being done in Sema because of expression folding.  If we instead push the invariant that the input TypeRepr should always be a TupleTypeRepr into the AST a number of nice cleanups fall out:

- The SIL Parser no longer accepts Swift 2-style type declarations
-  Parse is more cleanly able to reject invalid FunctionTypeReprs
- Clients of the AST can be assured the input type is always a TupleType so we can flush Swift 2 hacks
2018-06-13 18:41:20 -07:00
Mox Soini
596664f442 Flip static/class in error for using class method in protocol 2018-06-07 23:33:58 +03:00
Slava Pestov
7d49370d8e Remove duplicate diagnostic between Parse and Sema 2018-06-06 22:55:01 -07:00
Mox Soini
965124708a Better error message for 'class func/var' usage in protocols 2018-06-04 08:49:28 +03:00
Slava Pestov
8bf90f21d4 AST: Remove unneeded isDefinition and needsCapture methods from ValueDecl 2018-05-13 22:42:47 -07:00
Doug Gregor
9c395a47bd [AST] Report generic signature minimization errors through diagnostics.
Rather than crashing when a generic signature is found to be non-minimal,
report the non-minimal requirement via the normal diagnostics machinery so
we can properly test for it.

Fixes rdar://problem/36912347 by letting us track which cases are
non-minimal in the standard library explicitly, so we can better
decide whether it's worth implementing a complete solution.
2018-01-31 17:14:19 -08:00
Vedant Kumar
5573313df2 [SwiftPGO] Make profile counts available to SILGenProfiler
This makes it possible to look up the execution count corresponding to
an ASTNode through SILGenFunction. The profile reader itself is stored
in a SILGenModule: this doesn't seem like the best place for it, so
suggestions for improvement are welcome!

Next, we'll actually attach this data to SIL objects and pass it all
down to IRGen.
2017-09-26 10:54:01 -07:00
Alex Hoppen
faa1720c48 [Diagnostics] Adjustments for DeclBaseName
Adjust the definition of some diagnostics that are already called with
DeclBaseNames so that the implicit conversion from DeclBaseName to
Identifier is no longer needed.

Adjust the call side of diagnostics which don't have to deal with
special names to pass an Identifier to the diagnostic.
2017-05-31 15:58:46 +02:00
practicalswift
8cf0a14fdb [gardening] Remove 16 unused diagnostics 2017-03-05 00:43:52 +01:00
Jacob Bandes-Storch
c98e515734 [QoI] Improvements to function call & closure diagnostics (#7224) 2017-02-07 17:36:11 -08:00
Jacob Bandes-Storch
49f5251c73 [QoI] offer typo correction for platform conditionals 2017-01-12 09:07:53 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
practicalswift
cc852042c9 [gardening] Fix accidental trailing whitespace. 2016-10-29 10:22:58 +02:00
Mark Lacey
1005eb22ed Remove two notes that are no longer used.
The uses of these notes were removed in
8f2fbdc93a.
2016-07-06 16:40:59 -07:00
Xi Ge
9a91075509 Serialization: Add an error when group information for a specific source file is not found. 2016-03-09 17:09:34 -08:00
Michael Ilseman
de0062e437 [Diagnostics] Remove all categories
Diagnostic categories are entirely unused and arguably useless as
implemented, as they merely denote the sub-component of the
compiler.

As far as categorizing warnings are concerned, I'm abandoning the
effort for now, as the utility is marginal and Swift and the Swift
compiler are probalby not ready for these to be nailed down. For the
sake of cleanliness, the CATEGORY field is also stripped from
WARNINGS.

If there's a need for automatic identifying of compiler sub-components
for diagnstics in the future, there are better ways to do this.

NFC
2016-01-14 14:39:18 -08:00
practicalswift
1339b5403b Consistent use of header comment format.
Correct format:
//===--- Name of file - Description ----------------------------*- Lang -*-===//
2016-01-04 13:26:31 +01:00
Chris Lattner
5ce3de8dd6 remove & dial back three old bits of syntax auto-upgrading support:
1. Array type parsing for postfix array types Int[].  We now handle this
   in the parser, but remove the AST representation of this old form.  We
   also stop making vague promises about the future by saying that "fixed
   size arrays aren't supported... yet".  Removal of this fixes a compiler
   crasher too.

2. Remove the special case support for migrating @autoclosure from types
   to parameters, which was Swift 1.0/1.1 syntax.  The world has moved or
   we don't care anymore.

3. Remove upgrade support for # arguments (nee "backtick" arguments), which
   was a Swift 1.x'ism abolished in an effort to simplify method naming
   rules.

NFC on valid code.
2015-12-31 22:29:39 -08:00
Chris Lattner
b3e75dd121 Eliminate the stored "size" field in ArrayTypeRepr since it is always null, saving a word. NFC.
We should also eliminate the isOldSyntax as well, and just do the
error recovery in the parser (there is no need to retain the sugar here
anymore), but I'll do that as a separate change since it could be behavior
changing.
2015-12-31 21:27:24 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Chris Lattner
b0df3ef35e Improve mutability diagnostics for parameters to add a note inserting/changing
a 'var' modifier on the parameter, e.g.:

x.swift:44:5: error: cannot assign to 'let' value 'a'
  a = 1
  ~ ^
x.swift:43:8: note: change 'let' parameter to 'var' to make it mutable
func f(let a : Int) {
       ^~~
       var
x.swift:48:5: error: cannot assign to 'let' value 'b'
  b = 2
  ~ ^
x.swift:47:8: note: mark parameter with 'var' to make it mutable
func g(b : Int) {
       ^
       var

Also fix a bug where we'd incorrectly suggesting adding 'mutating' to a class
method when assigning to self in some cases.



Swift SVN r28926
2015-05-22 19:13:25 +00:00
Chris Lattner
43c7334abc fix two QoI issues:
- <rdar://problem/16306600> QoI: passing a 'let' value as an inout results in an unfriendly diagnostic
 - <rdar://problem/16927246> provide a fixit to change "let" to "var" if needing to mutate a variable

We now refer to an inout argument as such, e.g.:

t.swift:7:9: error: cannot pass 'let' value 'a' as inout argument
  swap(&a, &b)
        ^

we also produce a note with a fixit to rewrite let->var in trivial cases where mutation is
being assed for, e.g.:

t.swift:3:3: note: change 'let' to 'var' to make it mutable
  let a = 42
  ^~~
  var

The note is produced by both Sema and DI.



Swift SVN r27774
2015-04-26 21:51:50 +00:00
Jordan Rose
fac5a83bbf Allow capturing super in explicit closures and nested functions.
The previous commit enabled this; now it's just about removing the
restriction in the parser and tightening up code completion.

Using 'super' in a closure where 'self' is captured weak or unowned still
doesn't work; the reference to 'self' within the closure is treated as
strong regardless of how it's declared. Fixing this requires a cascade of
effort, so instead I just cloned rdar://problem/19755221.

rdar://problem/14883824

Swift SVN r25065
2015-02-07 03:56:11 +00:00
David Farler
87c3d7421f Refine static func and var syntax
rdar://problem/17198298

- Allow 'static' in protocol property and func requirements, but not 'class'.
- Allow 'static' methods in classes - they are 'class final'.
- Only allow 'class' methods in classes (or extensions of classes)
- Remove now unneeded diagnostics related to finding 'static' in previously banned places.
- Update relevant diagnostics to make the new rules clear.

Swift SVN r24260
2015-01-08 03:03:29 +00:00
Chris Lattner
8991456ff2 Switch infix/postfix/prefix to be declaration modifiers instead of attributes,
eliminating the @'s from them when used on func's.  This is progress towards
<rdar://problem/17527000> change operator declarations from "operator prefix" to "prefix operator" & make operator a keyword

This also consolidates rejection of custom operator definitions into one
place and makes it consistent, and adds postfix "?" to the list of rejected
operators.

This also changes the demangler to demangle weak/inout/postfix and related things
without the @.



Swift SVN r19929
2014-07-14 15:51:49 +00:00
Doug Gregor
4efc07c222 Promote warning about T[] array syntax to an error <rdar://problem/17461007>.
Swift SVN r19471
2014-07-02 18:09:28 +00:00