From 5dabb90390aa97c5f7a0681eff3464671340772d Mon Sep 17 00:00:00 2001 From: stevapple Date: Tue, 15 Jun 2021 06:23:18 +0800 Subject: [PATCH 1/7] Week 1 Sum-up --- README.md | 175 +++--------------- include/swift/AST/ASTContext.h | 4 + include/swift/AST/Attr.def | 5 + include/swift/AST/Attr.h | 25 +++ include/swift/AST/DiagnosticsParse.def | 4 + include/swift/Basic/FileTypes.def | 2 + include/swift/Basic/LangOptions.h | 6 + include/swift/Frontend/FrontendOptions.h | 6 + include/swift/Option/FrontendOptions.td | 4 + include/swift/Option/Options.td | 4 + include/swift/Parse/Parser.h | 14 ++ lib/AST/Attr.cpp | 2 + lib/Basic/FileTypes.cpp | 3 + lib/Driver/Driver.cpp | 1 + lib/Driver/ToolChains.cpp | 3 + .../ArgsToFrontendOptionsConverter.cpp | 5 + lib/Frontend/CompilerInvocation.cpp | 7 + lib/Frontend/FrontendOptions.cpp | 19 ++ lib/FrontendTool/FrontendTool.cpp | 38 ++++ lib/Parse/ParseDecl.cpp | 55 ++++++ lib/Parse/Parser.cpp | 7 + lib/Sema/TypeCheckAttr.cpp | 1 + lib/Sema/TypeCheckDeclOverride.cpp | 1 + lib/Serialization/ModuleFormat.h | 2 + lib/Serialization/Serialization.cpp | 1 + test/IDE/complete_decl_attribute.swift | 2 + 26 files changed, 243 insertions(+), 153 deletions(-) diff --git a/README.md b/README.md index 6e4685ee4780c..62b33fff97829 100644 --- a/README.md +++ b/README.md @@ -1,164 +1,33 @@ -Swift logo +# GSoC 2021: SwiftPM Support for Swift Packages -# Swift Programming Language +## Phase 1: Teaching the frontend to recognize package declaration syntax +### Determined tasks -| | **Architecture** | **main** | **Package** | -|---|:---:|:---:|:---:| -| **macOS** | x86_64 |[![Build Status](https://ci.swift.org/job/oss-swift-incremental-RA-macos/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-incremental-RA-macos)|[![Build Status](https://ci.swift.org/job/oss-swift-package-macos/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-macos)| -| **Ubuntu 16.04** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-16_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-16_04)|[![Build Status](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-16_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-16_04)| -| **Ubuntu 18.04** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-18_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-18_04)|[![Build Status](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-18_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-18_04)| -| **Ubuntu 20.04** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-package-ubuntu-20_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-ubuntu-20_04)|[![Build Status](https://ci.swift.org/job/oss-swift-package-ubuntu-20_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-ubuntu-20_04)| -| **CentOS 8** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-package-centos-8/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-centos-8)|[![Build Status](https://ci.swift.org/job/oss-swift-package-centos-8/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-centos-8)| -| **Amazon Linux 2** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-package-amazon-linux-2/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-amazon-linux-2)|[![Build Status](https://ci.swift.org/job/oss-swift-package-amazon-linux-2/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-amazon-linux-2)| +- [x] The `@package` attribute; +- [x] The `ignore-package-declaration` flag; +- [x] Basic syntax checking for `@package`; +- [ ] The `emit-package-declaration` flag and output format; +- [ ] Teach the parser to read labels from external syntax file; +- [ ] Teach the type checker to check against external syntax file. -**Swift Community-Hosted CI Platforms** +### Future tasks -| **OS** | **Architecture** | **Build** | -|---|:---:|:---:| -|**[Ubuntu 16.04 ](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/ppc64le_ubuntu_16_04.json)** | PPC64LE |[![Build Status](https://ci-external.swift.org/job/oss-swift-5.1-RA-linux-ubuntu-16.04-ppc64le/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-5.1-RA-linux-ubuntu-16.04-ppc64le)| -|**[Ubuntu 18.04](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/aarch64_ubuntu_18.04_docker.json)** | AArch64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-ubuntu-18.04-aarch64/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-ubuntu-18.04-aarch64)| -|**[Ubuntu 20.04](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/aarch64_ubuntu_20.04_docker.json)** | AArch64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-ubuntu-20.04-aarch64/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-ubuntu-20.04-aarch64)| -|**[CentOS 8 ](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/aarch64_centos_8_docker.json)** | AArch64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-centos8-aarch64/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-centos8-aarch64)| -|**[Amazon Linux 2](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/aarch64_amazon_linux_2_docker.json)** | AArch64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-amazon-linux-2-aarch64/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-amazon-linux-2-aarch64)| -|**[Android](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_ubuntu_16_04_LTS_android.json)** | ARMv7 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-android/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-android)| -|**[Android](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_ubuntu_16_04_LTS_android.json)** | AArch64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-android-arm64/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-android-arm64)| -|**[Windows 2019 (VS 2017)](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_windows_2019.json)** | x86_64 | [![Build Status](https://ci-external.swift.org/job/oss-swift-windows-x86_64/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-windows-x86_64)| -|**[Windows 2019 (VS 2019)](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_windows_2019_VS2019.json)** | x86_64 | [![Build Status](https://ci-external.swift.org/job/oss-swift-windows-x86_64-vs2019/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-windows-x86_64-vs2019)| +- [ ] Integrated driver support (probably move to the second phase?); +- [ ] Test SourceKit; +- [ ] Write unit tests. -**Swift TensorFlow Community-Hosted CI Platforms** +### Needs further investigation -| **OS** | **Architecture** | **Build** | -|---|:---:|:---:| -|**[Ubuntu 18.04](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_ubuntu_18_04_tensorflow.json)** | x86_64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-18.04-tensorflow/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-18.04-tensorflow)| -|**[macOS 10.13](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_macos_high_sierra_tensorflow.json)** | x86_64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-macOS-tensorflow/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-macOS-tensorflow)| +- How to import the syntax from SwiftPM? +- How to generate the syntax definition file? +- How to typecheck the attribute in an "isolated" context? -## Welcome to Swift +## Phase 2: Integrating the feature into the driver and package manager -Swift is a high-performance system programming language. It has a clean -and modern syntax, offers seamless access to existing C and Objective-C code -and frameworks, and is memory safe by default. +TBD. -Although inspired by Objective-C and many other languages, Swift is not itself a -C-derived language. As a complete and independent language, Swift packages core -features like flow control, data structures, and functions, with high-level -constructs like objects, protocols, closures, and generics. Swift embraces -modules, eliminating the need for headers and the code duplication they entail. +## Notes from the discussions -To learn more about the programming language, visit [swift.org](https://swift.org/documentation/). - -- [Contributing to Swift](#contributing-to-swift) -- [Getting Started](#getting-started) - - [Swift Toolchains](#swift-toolchains) - - [Build Failures](#build-failures) -- [Learning More](#learning-more) - -## Contributing to Swift - -Contributions to Swift are welcomed and encouraged! Please see the -[Contributing to Swift guide](https://swift.org/contributing/). - -To be a truly great community, [Swift.org](https://swift.org/) needs to welcome -developers from all walks of life, with different backgrounds, and with a wide -range of experience. A diverse and friendly community will have more great -ideas, more unique perspectives, and produce more great code. We will work -diligently to make the Swift community welcoming to everyone. - -To give clarity of what is expected of our members, Swift has adopted the -code of conduct defined by the Contributor Covenant. This document is used -across many open source communities, and we think it articulates our values -well. For more, see the [Code of Conduct](https://swift.org/code-of-conduct/). - -## Getting Started - -If you are interested in: -- Contributing fixes and features to the compiler: See our - [How to Submit Your First Pull Request guide](/docs/HowToGuides/FirstPullRequest.md). -- Building the compiler as a one-off: See our [Getting Started guide][]. -- Building a toolchain as a one-off: Follow the [Getting Started guide][] - up until the "Building the project" section. After that, follow the - instructions in the [Swift Toolchains](#swift-toolchains) section below. - -We also have an [FAQ](/docs/HowToGuides/FAQ.md) that answers common questions. - -[Getting Started guide]: /docs/HowToGuides/GettingStarted.md - -### Swift Toolchains - -#### Building - -Swift toolchains are created using the script -[build-toolchain](https://github.com/apple/swift/blob/main/utils/build-toolchain). This -script is used by swift.org's CI to produce snapshots and can allow for one to -locally reproduce such builds for development or distribution purposes. A typical -invocation looks like the following: - -``` - $ ./swift/utils/build-toolchain $BUNDLE_PREFIX -``` - -where ``$BUNDLE_PREFIX`` is a string that will be prepended to the build -date to give the bundle identifier of the toolchain's ``Info.plist``. For -instance, if ``$BUNDLE_PREFIX`` was ``com.example``, the toolchain -produced will have the bundle identifier ``com.example.YYYYMMDD``. It -will be created in the directory you run the script with a filename -of the form: ``swift-LOCAL-YYYY-MM-DD-a-osx.tar.gz``. - -Beyond building the toolchain, ``build-toolchain`` also supports the -following (non-exhaustive) set of useful options:: - -- ``--dry-run``: Perform a dry run build. This is off by default. -- ``--test``: Test the toolchain after it has been compiled. This is off by default. -- ``--distcc``: Use distcc to speed up the build by distributing the c++ part of - the swift build. This is off by default. -- ``--sccache``: Use sccache to speed up subsequent builds of the compiler by - caching more c++ build artifacts. This is off by default. - -More options may be added over time. Please pass ``--help`` to -``build-toolchain`` to see the full set of options. - -#### Installing into Xcode - -On macOS if one wants to install such a toolchain into Xcode: - -1. Untar and copy the toolchain to one of `/Library/Developer/Toolchains/` or - `~/Library/Developer/Toolchains/`. E.x.: - -``` - $ sudo tar -xzf swift-LOCAL-YYYY-MM-DD-a-osx.tar.gz -C / - $ tar -xzf swift-LOCAL-YYYY-MM-DD-a-osx.tar.gz -C ~/ -``` - -The script also generates an archive containing debug symbols which -can be installed over the main archive allowing symbolication of any -compiler crashes. - -``` - $ sudo tar -xzf swift-LOCAL-YYYY-MM-DD-a-osx-symbols.tar.gz -C / - $ tar -xzf swift-LOCAL-YYYY-MM-DD-a-osx-symbols.tar.gz -C ~/ -``` - -2. Specify the local toolchain for Xcode's use via `Xcode->Toolchains`. - -### Build Failures - -Try the suggestions in -[Troubleshooting build issues](/docs/HowToGuides/GettingStarted.md#troubleshooting-build-issues). - -Make sure you are using the -[correct release](/docs/HowToGuides/GettingStarted.md#installing-dependencies) -of Xcode. - -If you have changed Xcode versions but still encounter errors that appear to -be related to the Xcode version, try passing `--clean` to `build-script`. - -When a new version of Xcode is released, you can update your build without -recompiling the entire project by passing `--reconfigure` to `build-script`. - -## Learning More - -Be sure to look at the [documentation index](/docs/README.md) for a bird's eye -view of the available documentation. In particular, the documents titled -[Debugging the Swift Compiler](docs/DebuggingTheCompiler.md) and -[Continuous Integration for Swift](docs/ContinuousIntegration.md) are very -helpful to understand before submitting your first PR. +It seems best to provide package declaration syntax with a specific file from +SwiftPM, and we can expose it in some way that IDEs can also use. diff --git a/include/swift/AST/ASTContext.h b/include/swift/AST/ASTContext.h index 679df58b91870..da75358ae7d6c 100644 --- a/include/swift/AST/ASTContext.h +++ b/include/swift/AST/ASTContext.h @@ -83,6 +83,7 @@ namespace swift { class LazyIterableDeclContextData; class LazyMemberLoader; class ModuleDependencies; + class PackageAttr; class PatternBindingDecl; class PatternBindingInitializer; class SourceFile; @@ -314,6 +315,9 @@ class ASTContext final { llvm::DenseMap SILAutoDiffDerivativeFunctions; + /// Cache of `@package` attributes. + llvm::SetVector> PackageAttrs; + /// Cache of `@differentiable` attributes keyed by parameter indices. Used to /// diagnose duplicate `@differentiable` attributes for the same key. llvm::DenseMap, DifferentiableAttr *> diff --git a/include/swift/AST/Attr.def b/include/swift/AST/Attr.def index 515e06a3ba171..d2bf849089e08 100644 --- a/include/swift/AST/Attr.def +++ b/include/swift/AST/Attr.def @@ -659,6 +659,11 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(spawn, Spawn, APIBreakingToAdd | APIBreakingToRemove, 117) +DECL_ATTR(package, Package, OnImport | + ABIStableToAdd | ABIStableToRemove | + APIStableToAdd | APIStableToRemove | + NotSerialized, 118) + #undef TYPE_ATTR #undef DECL_ATTR_ALIAS #undef CONTEXTUAL_DECL_ATTR_ALIAS diff --git a/include/swift/AST/Attr.h b/include/swift/AST/Attr.h index 3ba1a102e73b7..c39478c66d235 100644 --- a/include/swift/AST/Attr.h +++ b/include/swift/AST/Attr.h @@ -1677,6 +1677,31 @@ class OriginallyDefinedInAttr: public DeclAttribute { } }; +/// The `@package` attribute implies its following imports has +/// external package dependencies. +/// +/// Syntax definition is passed in on frontend calls. +class PackageAttr: public DeclAttribute { +public: + PackageAttr(SourceLoc AtLoc, SourceRange Range, + StringRef PackageDeclaration, + bool Implicit) + : DeclAttribute(DAK_Package, AtLoc, Range, Implicit), + PackageDeclaration(PackageDeclaration) {} + + /// The package declaration string. + const StringRef PackageDeclaration; + + /// The getter of `PackageDeclaration`. + const StringRef getPackageDeclaration() { + return PackageDeclaration; + } + + static bool classof(const DeclAttribute *DA) { + return DA->getKind() == DAK_Package; + } +}; + /// Attribute that marks a function as differentiable. /// /// Examples: diff --git a/include/swift/AST/DiagnosticsParse.def b/include/swift/AST/DiagnosticsParse.def index 423b42abeabad..85de3116a8beb 100644 --- a/include/swift/AST/DiagnosticsParse.def +++ b/include/swift/AST/DiagnosticsParse.def @@ -1844,5 +1844,9 @@ ERROR(expected_closure_literal,none, ERROR(expected_multiple_closures_block_rbrace,none, "expected '}' at the end of a trailing closures block", ()) +// Package declaration errors +ERROR(package_declaration_not_allowed,none, + "package declaration is not allowed", ()) + #define UNDEFINE_DIAGNOSTIC_MACROS #include "DefineDiagnosticMacros.h" diff --git a/include/swift/Basic/FileTypes.def b/include/swift/Basic/FileTypes.def index 158c891df3103..28d5255220110 100644 --- a/include/swift/Basic/FileTypes.def +++ b/include/swift/Basic/FileTypes.def @@ -77,6 +77,8 @@ TYPE("json-dependencies", JSONDependencies, "dependencies.json", // Complete feature information for the given Swift compiler. TYPE("json-features", JSONFeatures, "features.json", "") +// Complete package dependency information for the given Swift files as JSON. +TYPE("package-declarations", PackageDeclarations, "package-declarations.json", "") TYPE("index-data", IndexData, "", "") TYPE("index-unit-output-path", IndexUnitOutputPath, "", "") diff --git a/include/swift/Basic/LangOptions.h b/include/swift/Basic/LangOptions.h index 8b9e221606e29..d3993ee5a16d5 100644 --- a/include/swift/Basic/LangOptions.h +++ b/include/swift/Basic/LangOptions.h @@ -410,6 +410,12 @@ namespace swift { // FrontendOptions. bool AllowModuleWithCompilerErrors = false; + // Allow @package attribute in the file. + bool AllowPackageDeclaration = false; + + // Ingore @package attributes in the file. + bool IgnorePackageDeclarations = false; + /// A helper enum to represent whether or not we customized the default /// ASTVerifier behavior via a frontend flag. By default, we do not /// customize. diff --git a/include/swift/Frontend/FrontendOptions.h b/include/swift/Frontend/FrontendOptions.h index 869870007c579..42aeee6ba8d9d 100644 --- a/include/swift/Frontend/FrontendOptions.h +++ b/include/swift/Frontend/FrontendOptions.h @@ -154,6 +154,8 @@ class FrontendOptions { ScanDependencies, ///< Scan dependencies of Swift source files PrintVersion, ///< Print version information. PrintFeature, ///< Print supported feature of this compiler + + PrintPackageDeclarations ///< Print package declarations from the Swift source file }; /// Indicates the action the user requested that the frontend perform. @@ -409,6 +411,10 @@ class FrontendOptions { /// which are inherited through classes or default implementations. bool SkipInheritedDocs = false; + /// Package declarations. + /// TODO: Complete the description. + bool IgnorePackageDeclarations = false; + private: static bool canActionEmitDependencies(ActionType); static bool canActionEmitReferenceDependencies(ActionType); diff --git a/include/swift/Option/FrontendOptions.td b/include/swift/Option/FrontendOptions.td index 97c6713d40d30..2694b32dec3b1 100644 --- a/include/swift/Option/FrontendOptions.td +++ b/include/swift/Option/FrontendOptions.td @@ -825,4 +825,8 @@ def new_driver_path : Separate<["-"], "new-driver-path">, MetaVarName<"">, HelpText<"Path of the new driver to be used">; +def ignore_package_declarations : Flag<["-"], "ignore-package-declarations">, + HelpText<"Ignore all package declarations in the file, assuming all external" + "dependencies are provided as modules.">; + } // end let Flags = [FrontendOption, NoDriverOption, HelpHidden] diff --git a/include/swift/Option/Options.td b/include/swift/Option/Options.td index 4bdb51571e9b7..838af5b7b4a63 100644 --- a/include/swift/Option/Options.td +++ b/include/swift/Option/Options.td @@ -1005,6 +1005,10 @@ def dump_pcm : Flag<["-"], "dump-pcm">, HelpText<"Dump debugging information about a precompiled Clang module">, ModeOpt, Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>; +def print_package_declarations : Flag<["-"], "print-package-declarations">, + HelpText<"Print all package declarations in the file.">, + ModeOpt, + Flags<[FrontendOption, NoInteractiveOption, DoesNotAffectIncrementalBuild]>; // Other Modes def repl : Flag<["-"], "repl">, diff --git a/include/swift/Parse/Parser.h b/include/swift/Parse/Parser.h index 23e8c7d5f36cd..bb14632421e6e 100644 --- a/include/swift/Parse/Parser.h +++ b/include/swift/Parse/Parser.h @@ -189,6 +189,16 @@ class Parser { bool allowTopLevelCode() const; + bool ignorePackageDeclarations() const { + return Context.LangOpts.IgnorePackageDeclarations; + } + bool allowPackageDeclaration() const { + return Context.LangOpts.AllowPackageDeclaration || + Context.LangOpts.IgnorePackageDeclarations; + } + + void registerPackageDeclaration(PackageAttr *Package); + const std::vector &getSplitTokens() const { return SplitTokens; } void markSplitToken(tok Kind, StringRef Txt); @@ -1035,6 +1045,10 @@ class Parser { ParserResult parseImplementsAttribute(SourceLoc AtLoc, SourceLoc Loc); + /// Parse the @package attribute. + ParserResult parsePackageAttribute(SourceLoc AtLoc, + SourceLoc Loc); + /// Parse the @differentiable attribute. ParserResult parseDifferentiableAttribute(SourceLoc AtLoc, SourceLoc Loc); diff --git a/lib/AST/Attr.cpp b/lib/AST/Attr.cpp index 008fc36e5f9cd..82860b8c98b95 100644 --- a/lib/AST/Attr.cpp +++ b/lib/AST/Attr.cpp @@ -1248,6 +1248,8 @@ StringRef DeclAttribute::getAttrName() const { return "transpose"; case DAK_CompletionHandlerAsync: return "completionHandlerAsync"; + case DAK_Package: + return "package"; } llvm_unreachable("bad DeclAttrKind"); } diff --git a/lib/Basic/FileTypes.cpp b/lib/Basic/FileTypes.cpp index 3d6151940a832..0025edff8b027 100644 --- a/lib/Basic/FileTypes.cpp +++ b/lib/Basic/FileTypes.cpp @@ -84,6 +84,7 @@ bool file_types::isTextual(ID Id) { case file_types::TY_SwiftOverlayFile: case file_types::TY_JSONDependencies: case file_types::TY_JSONFeatures: + case file_types::TY_PackageDeclarations: return true; case file_types::TY_Image: case file_types::TY_Object: @@ -157,6 +158,7 @@ bool file_types::isAfterLLVM(ID Id) { case file_types::TY_JSONDependencies: case file_types::TY_JSONFeatures: case file_types::TY_IndexUnitOutputPath: + case file_types::TY_PackageDeclarations: return false; case file_types::TY_INVALID: llvm_unreachable("Invalid type ID."); @@ -208,6 +210,7 @@ bool file_types::isPartOfSwiftCompilation(ID Id) { case file_types::TY_JSONDependencies: case file_types::TY_JSONFeatures: case file_types::TY_IndexUnitOutputPath: + case file_types::TY_PackageDeclarations: return false; case file_types::TY_INVALID: llvm_unreachable("Invalid type ID."); diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 8eb012e6d86df..31b29f00d465d 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -2017,6 +2017,7 @@ void Driver::buildActions(SmallVectorImpl &TopLevelActions, case file_types::TY_SwiftOverlayFile: case file_types::TY_JSONDependencies: case file_types::TY_JSONFeatures: + case file_types::TY_PackageDeclarations: // We could in theory handle assembly or LLVM input, but let's not. // FIXME: What about LTO? Diags.diagnose(SourceLoc(), diag::error_unexpected_input_file, diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index 80a81f37617c1..d3eff489f0949 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -632,6 +632,8 @@ const char *ToolChain::JobContext::computeFrontendModeForCompile() const { return "-typecheck"; case file_types::TY_Remapping: return "-update-code"; + case file_types::TY_PackageDeclarations: + return "-print-package-declarations"; case file_types::TY_Nothing: // We were told to output nothing, so get the last mode option and use that. if (const Arg *A = Args.getLastArg(options::OPT_modes_Group)) @@ -896,6 +898,7 @@ ToolChain::constructInvocation(const BackendJobAction &job, case file_types::TY_IndexData: case file_types::TY_JSONDependencies: case file_types::TY_JSONFeatures: + case file_types::TY_PackageDeclarations: llvm_unreachable("Cannot be output from backend job"); case file_types::TY_Swift: case file_types::TY_dSYM: diff --git a/lib/Frontend/ArgsToFrontendOptionsConverter.cpp b/lib/Frontend/ArgsToFrontendOptionsConverter.cpp index 652133ea7d275..7757944292e58 100644 --- a/lib/Frontend/ArgsToFrontendOptionsConverter.cpp +++ b/lib/Frontend/ArgsToFrontendOptionsConverter.cpp @@ -267,6 +267,8 @@ bool ArgsToFrontendOptionsConverter::convert( Opts.Static = Args.hasArg(OPT_static); + Opts.IgnorePackageDeclarations = Args.hasArg(OPT_ignore_package_declarations); + return false; } @@ -463,6 +465,9 @@ ArgsToFrontendOptionsConverter::determineRequestedAction(const ArgList &args) { return FrontendOptions::ActionType::TypecheckModuleFromInterface; if (Opt.matches(OPT_emit_supported_features)) return FrontendOptions::ActionType::PrintFeature; + + if (Opt.matches(OPT_print_package_declarations)) + return FrontendOptions::ActionType::PrintPackageDeclarations; llvm_unreachable("Unhandled mode option"); } diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 46c31e8705844..357e1c9d0c26e 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -743,6 +743,13 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args, Opts.VerifySyntaxTree = true; } + if (FrontendOpts.RequestedAction == FrontendOptions::ActionType::PrintPackageDeclarations) { + Opts.AllowPackageDeclaration = true; + } + if (FrontendOpts.IgnorePackageDeclarations) { + Opts.IgnorePackageDeclarations = true; + } + // Configure lexing to parse and remember comments if: // - Emitting a swiftdoc/swiftsourceinfo // - Performing index-while-building diff --git a/lib/Frontend/FrontendOptions.cpp b/lib/Frontend/FrontendOptions.cpp index 452c1e5b99f87..ca73b8935e61f 100644 --- a/lib/Frontend/FrontendOptions.cpp +++ b/lib/Frontend/FrontendOptions.cpp @@ -43,6 +43,7 @@ bool FrontendOptions::needsProperModuleName(ActionType action) { case ActionType::DumpTypeRefinementContexts: case ActionType::DumpPCM: case ActionType::EmitPCH: + case ActionType::PrintPackageDeclarations: return false; case ActionType::EmitSILGen: case ActionType::EmitSIL: @@ -82,6 +83,7 @@ bool FrontendOptions::shouldActionOnlyParse(ActionType action) { case ActionType::ScanDependencies: case ActionType::PrintVersion: case ActionType::PrintFeature: + case ActionType::PrintPackageDeclarations: return true; default: return false; @@ -104,6 +106,7 @@ bool FrontendOptions::doesActionRequireSwiftStandardLibrary(ActionType action) { case ActionType::CompileModuleFromInterface: case ActionType::TypecheckModuleFromInterface: case ActionType::PrintFeature: + case ActionType::PrintPackageDeclarations: return false; case ActionType::ResolveImports: case ActionType::Typecheck: @@ -169,6 +172,7 @@ bool FrontendOptions::doesActionRequireInputs(ActionType action) { case ActionType::EmitBC: case ActionType::EmitObject: case ActionType::DumpTypeInfo: + case ActionType::PrintPackageDeclarations: return true; } llvm_unreachable("Unknown ActionType"); @@ -211,6 +215,7 @@ bool FrontendOptions::doesActionPerformEndOfPipelineActions(ActionType action) { case ActionType::EmitBC: case ActionType::EmitObject: case ActionType::DumpTypeInfo: + case ActionType::PrintPackageDeclarations: return true; } llvm_unreachable("Unknown ActionType"); @@ -311,6 +316,9 @@ FrontendOptions::formatForPrincipalOutputFileForAction(ActionType action) { return TY_JSONDependencies; case ActionType::PrintFeature: return TY_JSONFeatures; + + case ActionType::PrintPackageDeclarations: + return TY_PackageDeclarations; } llvm_unreachable("unhandled action"); } @@ -352,6 +360,7 @@ bool FrontendOptions::canActionEmitDependencies(ActionType action) { case ActionType::EmitImportedModules: case ActionType::EmitPCM: case ActionType::ScanDependencies: + case ActionType::PrintPackageDeclarations: return true; } llvm_unreachable("unhandled action"); @@ -379,6 +388,7 @@ bool FrontendOptions::canActionEmitReferenceDependencies(ActionType action) { case ActionType::ScanDependencies: case ActionType::PrintVersion: case ActionType::PrintFeature: + case ActionType::PrintPackageDeclarations: return false; case ActionType::Typecheck: case ActionType::MergeModules: @@ -428,6 +438,7 @@ bool FrontendOptions::canActionEmitModuleSummary(ActionType action) { case ActionType::EmitModuleOnly: case ActionType::PrintVersion: case ActionType::PrintFeature: + case ActionType::PrintPackageDeclarations: return false; case ActionType::EmitSIL: case ActionType::EmitSIB: @@ -464,6 +475,7 @@ bool FrontendOptions::canActionEmitObjCHeader(ActionType action) { case ActionType::ScanDependencies: case ActionType::PrintVersion: case ActionType::PrintFeature: + case ActionType::PrintPackageDeclarations: return false; case ActionType::Typecheck: case ActionType::MergeModules: @@ -504,6 +516,7 @@ bool FrontendOptions::canActionEmitLoadedModuleTrace(ActionType action) { case ActionType::ScanDependencies: case ActionType::PrintVersion: case ActionType::PrintFeature: + case ActionType::PrintPackageDeclarations: return false; case ActionType::ResolveImports: case ActionType::Typecheck: @@ -550,6 +563,7 @@ bool FrontendOptions::canActionEmitModule(ActionType action) { case ActionType::ScanDependencies: case ActionType::PrintVersion: case ActionType::PrintFeature: + case ActionType::PrintPackageDeclarations: return false; case ActionType::MergeModules: case ActionType::EmitModuleOnly: @@ -596,6 +610,7 @@ bool FrontendOptions::canActionEmitInterface(ActionType action) { case ActionType::DumpPCM: case ActionType::ScanDependencies: case ActionType::PrintFeature: + case ActionType::PrintPackageDeclarations: return false; case ActionType::Typecheck: case ActionType::MergeModules: @@ -645,6 +660,7 @@ bool FrontendOptions::doesActionProduceOutput(ActionType action) { case ActionType::DumpPCM: case ActionType::ScanDependencies: case ActionType::PrintFeature: + case ActionType::PrintPackageDeclarations: return true; case ActionType::NoneAction: @@ -694,6 +710,7 @@ bool FrontendOptions::doesActionProduceTextualOutput(ActionType action) { case ActionType::ScanDependencies: case ActionType::PrintVersion: case ActionType::PrintFeature: + case ActionType::PrintPackageDeclarations: return true; } llvm_unreachable("unhandled action"); @@ -721,6 +738,7 @@ bool FrontendOptions::doesActionGenerateSIL(ActionType action) { case ActionType::ScanDependencies: case ActionType::PrintVersion: case ActionType::PrintFeature: + case ActionType::PrintPackageDeclarations: return false; case ActionType::EmitSILGen: case ActionType::EmitSIBGen: @@ -770,6 +788,7 @@ bool FrontendOptions::doesActionGenerateIR(ActionType action) { case ActionType::ScanDependencies: case ActionType::PrintVersion: case ActionType::PrintFeature: + case ActionType::PrintPackageDeclarations: return false; case ActionType::Immediate: case ActionType::REPL: diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp index 12202e7cca5d9..5f4f948156aaa 100644 --- a/lib/FrontendTool/FrontendTool.cpp +++ b/lib/FrontendTool/FrontendTool.cpp @@ -41,6 +41,7 @@ #include "swift/Basic/Dwarf.h" #include "swift/Basic/Edit.h" #include "swift/Basic/FileSystem.h" +#include "swift/Basic/JSONSerialization.h" #include "swift/Basic/LLVMInitialize.h" #include "swift/Basic/ParseableOutput.h" #include "swift/Basic/Platform.h" @@ -1139,6 +1140,41 @@ static bool performScanDependencies(CompilerInstance &Instance) { } } +template <> struct swift::json::ObjectTraits> { + static void mapping(Output &out, + std::tuple &value) { + out.mapRequired("file", std::get<0>(value)); + out.mapRequired("line", std::get<1>(value)); + StringRef declaration = std::get<2>(value)->getPackageDeclaration(); + out.mapRequired("declaration", declaration); + } +}; + +template <> +struct swift::json::ArrayTraits>> { + static size_t size(Output &out, llvm::SetVector> &seq) { + return seq.size(); + } + static std::tuple & + element(Output &out, llvm::SetVector> &seq, size_t index) { + return const_cast &>(seq[index]); + } +}; + +static bool printPackageDeclarations(CompilerInstance &Instance) { + for (auto *file : Instance.getMainModule()->getFiles()) { + if (auto *SF = dyn_cast(file)) + (void)SF->getTopLevelDecls(); + } + auto &ctx = Instance.getASTContext(); + if (ctx.hadError()) + return true; + + json::Output Out(llvm::outs(), /*UserInfo=*/{}, /*PrettyPrint=*/true); + Out << ctx.PackageAttrs; + return false; +} + static bool performParseOnly(ModuleDecl &MainModule) { // A -parse invocation only cares about the side effects of parsing, so // force the parsing of all the source files. @@ -1222,6 +1258,8 @@ static bool performAction(CompilerInstance &Instance, // MARK: Dependency Scanning Actions case FrontendOptions::ActionType::ScanDependencies: return performScanDependencies(Instance); + case FrontendOptions::ActionType::PrintPackageDeclarations: + return printPackageDeclarations(Instance); // MARK: General Compilation Actions case FrontendOptions::ActionType::Parse: diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 1b012a6e6ee96..f18cef36aa916 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -843,6 +843,44 @@ Parser::parseImplementsAttribute(SourceLoc AtLoc, SourceLoc Loc) { MemberNameLoc)); } +/// Parse a `@package` attribute. +ParserResult +Parser::parsePackageAttribute(SourceLoc AtLoc, SourceLoc Loc) { + StringRef AttrName = "package"; + SourceLoc lParenLoc; + SourceLoc rParenLoc; + SmallVector Args; + SmallVector ArgLabels; + SmallVector ArgLabelLocs; + SmallVector TrailingClosures; + ParserStatus Status; + if (Tok.isNot(tok::l_paren)) { + diagnose(Loc, diag::attr_expected_lparen, AttrName, + /*DeclModifier=*/false); + Status.setIsParseError(); + return Status; + } + Status = parseExprList(tok::l_paren, tok::r_paren, + /*isPostfix=*/true, /*isExprBasic*/true, + lParenLoc, Args, ArgLabels, + ArgLabelLocs, rParenLoc, TrailingClosures, + SyntaxKind::TupleExprElementList); + assert(TrailingClosures.size() == 0 && + "package attribute parsing shouldn't allow trailing closure"); + + // TODO: Examining package declaration syntax + if (Status.isError()) { + return Status; + } + + SourceRange range = SourceRange(lParenLoc, rParenLoc); + StringRef declaration = SourceMgr.extractText( + Lexer::getCharSourceRangeFromSourceRange(SourceMgr, range)); + + return ParserResult( + new (Context) PackageAttr(AtLoc, range, declaration, /*implicit*/false)); +} + /// Parse a `@differentiable` attribute, returning true on error. /// /// \verbatim @@ -2734,6 +2772,23 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc, Attributes.add(attr); break; } + + case DAK_Package: { + if (!allowPackageDeclaration()) { + diagnose(Loc, diag::package_declaration_not_allowed); + return false; + } + + ParserResult Package; + // Parse package declaration + Package = parsePackageAttribute(AtLoc, Loc); + + if (Package.isNonNull() && !ignorePackageDeclarations()) { + registerPackageDeclaration(Package.get()); + Attributes.add(Package.get()); + } + break; + } } if (DuplicateAttribute) { diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp index 5d54a6dff4721..2c1250302c3e4 100644 --- a/lib/Parse/Parser.cpp +++ b/lib/Parse/Parser.cpp @@ -568,6 +568,13 @@ bool Parser::allowTopLevelCode() const { return SF.isScriptMode(); } +void Parser::registerPackageDeclaration(PackageAttr *Package) { + unsigned BufferID = SourceMgr.findBufferContainingLoc(Package->AtLoc); + StringRef File = SourceMgr.getIdentifierForBuffer(BufferID); + unsigned Line = SourceMgr.getPresumedLineAndColumnForLoc(Package->AtLoc, BufferID).first; + Context.PackageAttrs.insert(std::make_tuple(File, Line, Package)); +} + const Token &Parser::peekToken() { return L->peekNextToken(); } diff --git a/lib/Sema/TypeCheckAttr.cpp b/lib/Sema/TypeCheckAttr.cpp index 6fca46e353d5b..5da5374f487cd 100644 --- a/lib/Sema/TypeCheckAttr.cpp +++ b/lib/Sema/TypeCheckAttr.cpp @@ -86,6 +86,7 @@ class AttributeChecker : public AttributeVisitor { IGNORED_ATTR(ObjCBridged) IGNORED_ATTR(ObjCNonLazyRealization) IGNORED_ATTR(ObjCRuntimeName) + IGNORED_ATTR(Package) IGNORED_ATTR(RawDocComment) IGNORED_ATTR(RequiresStoredPropertyInits) IGNORED_ATTR(RestatedObjCConformance) diff --git a/lib/Sema/TypeCheckDeclOverride.cpp b/lib/Sema/TypeCheckDeclOverride.cpp index 753d99b605ef5..e3cd7b334fd8d 100644 --- a/lib/Sema/TypeCheckDeclOverride.cpp +++ b/lib/Sema/TypeCheckDeclOverride.cpp @@ -1476,6 +1476,7 @@ namespace { UNINTERESTING_ATTR(ObjCBridged) UNINTERESTING_ATTR(Optional) UNINTERESTING_ATTR(Override) + UNINTERESTING_ATTR(Package) UNINTERESTING_ATTR(RawDocComment) UNINTERESTING_ATTR(Required) UNINTERESTING_ATTR(Convenience) diff --git a/lib/Serialization/ModuleFormat.h b/lib/Serialization/ModuleFormat.h index ce8abc3e1635f..1637e01949cfe 100644 --- a/lib/Serialization/ModuleFormat.h +++ b/lib/Serialization/ModuleFormat.h @@ -1846,6 +1846,8 @@ namespace decls_block { using ClangImporterSynthesizedTypeDeclAttrLayout = BCRecordLayout; using PrivateImportDeclAttrLayout = BCRecordLayout; + using PackageDeclAttrLayout = BCRecordLayout; + using ProjectedValuePropertyDeclAttrLayout = BCRecordLayout< ProjectedValueProperty_DECL_ATTR, BCFixed<1>, // isImplicit diff --git a/lib/Serialization/Serialization.cpp b/lib/Serialization/Serialization.cpp index 79c8bc99fbfaa..42b185292b213 100644 --- a/lib/Serialization/Serialization.cpp +++ b/lib/Serialization/Serialization.cpp @@ -2318,6 +2318,7 @@ class Serializer::DeclSerializer : public DeclVisitor { case DAK_RestatedObjCConformance: case DAK_ClangImporterSynthesizedType: case DAK_PrivateImport: + case DAK_Package: llvm_unreachable("cannot serialize attribute"); case DAK_Count: diff --git a/test/IDE/complete_decl_attribute.swift b/test/IDE/complete_decl_attribute.swift index ba2a9f4594a97..9bbc199f9447a 100644 --- a/test/IDE/complete_decl_attribute.swift +++ b/test/IDE/complete_decl_attribute.swift @@ -254,6 +254,7 @@ struct _S { // ON_MEMBER_LAST-DAG: Keyword/None: transpose[#Declaration Attribute#]; name=transpose // ON_MEMBER_LAST-DAG: Keyword/None: noDerivative[#Declaration Attribute#]; name=noDerivative // ON_MEMBER_LAST-DAG: Keyword/None: Sendable[#Declaration Attribute#]; name=Sendable +// ON_MEMBER_LAST-DAG: Keyword/None: Package[#Declaration Attribute#]; name=Package // ON_MEMBER_LAST-NOT: Keyword // ON_MEMBER_LAST: Decl[Struct]/CurrModule: MyStruct[#MyStruct#]; name=MyStruct // ON_MEMBER_LAST-NOT: Decl[PrecedenceGroup] @@ -304,6 +305,7 @@ func dummy2() {} // KEYWORD_LAST-DAG: Keyword/None: transpose[#Declaration Attribute#]; name=transpose // KEYWORD_LAST-DAG: Keyword/None: noDerivative[#Declaration Attribute#]; name=noDerivative // KEYWORD_LAST-DAG: Keyword/None: Sendable[#Declaration Attribute#]; name=Sendable +// KEYWORD_LAST-DAG: Keyword/None: Package[#Declaration Attribute#]; name=Package // KEYWORD_LAST-NOT: Keyword // KEYWORD_LAST: Decl[Struct]/CurrModule: MyStruct[#MyStruct#]; name=MyStruct // KEYWORD_LAST: End completions From e37464491c2527468e167387672c822b5b212ff8 Mon Sep 17 00:00:00 2001 From: stevapple Date: Tue, 22 Jun 2021 01:31:34 +0800 Subject: [PATCH 2/7] Try some Sema checks --- include/swift/AST/Attr.h | 24 +++++++++++++++++++----- include/swift/AST/DiagnosticsSema.def | 8 ++++++++ include/swift/AST/Import.h | 3 +++ lib/FrontendTool/FrontendTool.cpp | 1 + lib/Parse/ParseDecl.cpp | 19 +++++++++++++++---- lib/Sema/ImportResolution.cpp | 3 +++ lib/Sema/TypeCheckAttr.cpp | 27 ++++++++++++++++++++++++++- 7 files changed, 75 insertions(+), 10 deletions(-) diff --git a/include/swift/AST/Attr.h b/include/swift/AST/Attr.h index c39478c66d235..af6a117b18ec4 100644 --- a/include/swift/AST/Attr.h +++ b/include/swift/AST/Attr.h @@ -1681,22 +1681,36 @@ class OriginallyDefinedInAttr: public DeclAttribute { /// external package dependencies. /// /// Syntax definition is passed in on frontend calls. -class PackageAttr: public DeclAttribute { +class PackageAttr final: public DeclAttribute, + public TrailingCallArguments { + /// The package declaration string. + const StringRef PackageDeclaration; + + unsigned NumArgLabels : 16; + Expr *Arg; + public: PackageAttr(SourceLoc AtLoc, SourceRange Range, StringRef PackageDeclaration, + Expr * Arg, + ArrayRef ArgLabels, + ArrayRef ArgLabelLocs, bool Implicit) : DeclAttribute(DAK_Package, AtLoc, Range, Implicit), - PackageDeclaration(PackageDeclaration) {} - - /// The package declaration string. - const StringRef PackageDeclaration; + PackageDeclaration(PackageDeclaration), + Arg(Arg) { + NumArgLabels = ArgLabels.size(); + initializeCallArguments(ArgLabels, ArgLabelLocs); + } /// The getter of `PackageDeclaration`. const StringRef getPackageDeclaration() { return PackageDeclaration; } + Expr *getArg() const { return Arg; } + unsigned getNumArguments() const { return NumArgLabels; } + static bool classof(const DeclAttribute *DA) { return DA->getKind() == DAK_Package; } diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index d986619041573..4436ff6e17750 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -5901,6 +5901,14 @@ ERROR(wrap_invalid_attr_added_by_access_note, none, "though it was " WHICH_ACCESS_NOTE(1), (DiagnosticInfo *, StringRef, StringRef, DescriptiveDeclKind)) +// Package diagnostics +NOTE(package_declaration, none, + "import '%0' from '%1'", + (StringRef, StringRef)) + +ERROR(invalid_package_declaration, none, + "%0", (StringRef)) + #undef WHICH_ACCESS_NOTE #define UNDEFINE_DIAGNOSTIC_MACROS diff --git a/include/swift/AST/Import.h b/include/swift/AST/Import.h index b6a1f7a2d352a..1e5e92fb10aa7 100644 --- a/include/swift/AST/Import.h +++ b/include/swift/AST/Import.h @@ -80,6 +80,9 @@ enum class ImportFlags { /// implementation detail of this file. SPIAccessControl = 0x10, + /// The module is explicitly marked to be imported from SwiftPM. + Package = 0x20, + /// Used for DenseMap. Reserved = 0x80 }; diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp index 5f4f948156aaa..d24262ea166d5 100644 --- a/lib/FrontendTool/FrontendTool.cpp +++ b/lib/FrontendTool/FrontendTool.cpp @@ -1172,6 +1172,7 @@ static bool printPackageDeclarations(CompilerInstance &Instance) { json::Output Out(llvm::outs(), /*UserInfo=*/{}, /*PrettyPrint=*/true); Out << ctx.PackageAttrs; + llvm::outs() << "\n"; return false; } diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index f18cef36aa916..d212bb7c4257c 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -849,9 +849,9 @@ Parser::parsePackageAttribute(SourceLoc AtLoc, SourceLoc Loc) { StringRef AttrName = "package"; SourceLoc lParenLoc; SourceLoc rParenLoc; - SmallVector Args; - SmallVector ArgLabels; - SmallVector ArgLabelLocs; + SmallVector Args; + SmallVector ArgLabels; + SmallVector ArgLabelLocs; SmallVector TrailingClosures; ParserStatus Status; if (Tok.isNot(tok::l_paren)) { @@ -877,8 +877,19 @@ Parser::parsePackageAttribute(SourceLoc AtLoc, SourceLoc Loc) { StringRef declaration = SourceMgr.extractText( Lexer::getCharSourceRangeFromSourceRange(SourceMgr, range)); + SmallVector argLabelsScratch; + SmallVector argLabelLocsScratch; + ArrayRef args = Args; + ArrayRef argLabels = ArgLabels; + ArrayRef argLabelLocs = ArgLabelLocs; + Expr *arg = packSingleArgument(Context, lParenLoc, + args, argLabels, argLabelLocs, + rParenLoc, {}, /*implicit*/false, + argLabelsScratch, argLabelLocsScratch); + return ParserResult( - new (Context) PackageAttr(AtLoc, range, declaration, /*implicit*/false)); + new (Context) PackageAttr(AtLoc, range, declaration, arg, + ArgLabels, ArgLabelLocs, /*implicit*/false)); } /// Parse a `@differentiable` attribute, returning true on error. diff --git a/lib/Sema/ImportResolution.cpp b/lib/Sema/ImportResolution.cpp index 6a017f687b8ac..192305b112a3a 100644 --- a/lib/Sema/ImportResolution.cpp +++ b/lib/Sema/ImportResolution.cpp @@ -535,6 +535,9 @@ UnboundImport::UnboundImport(ImportDecl *ID) if (ID->getAttrs().hasAttribute()) import.options |= ImportFlags::ImplementationOnly; + if (ID->getAttrs().hasAttribute()) + import.options |= ImportFlags::Package; + if (auto *privateImportAttr = ID->getAttrs().getAttribute()) { import.options |= ImportFlags::PrivateImport; diff --git a/lib/Sema/TypeCheckAttr.cpp b/lib/Sema/TypeCheckAttr.cpp index 5da5374f487cd..69298a85953ca 100644 --- a/lib/Sema/TypeCheckAttr.cpp +++ b/lib/Sema/TypeCheckAttr.cpp @@ -27,6 +27,7 @@ #include "swift/AST/GenericEnvironment.h" #include "swift/AST/GenericSignatureBuilder.h" #include "swift/AST/ImportCache.h" +#include "swift/AST/Module.h" #include "swift/AST/ModuleNameLookup.h" #include "swift/AST/NameLookup.h" #include "swift/AST/NameLookupRequests.h" @@ -86,7 +87,6 @@ class AttributeChecker : public AttributeVisitor { IGNORED_ATTR(ObjCBridged) IGNORED_ATTR(ObjCNonLazyRealization) IGNORED_ATTR(ObjCRuntimeName) - IGNORED_ATTR(Package) IGNORED_ATTR(RawDocComment) IGNORED_ATTR(RequiresStoredPropertyInits) IGNORED_ATTR(RestatedObjCConformance) @@ -262,6 +262,8 @@ class AttributeChecker : public AttributeVisitor { void visitReasyncAttr(ReasyncAttr *attr); void visitNonisolatedAttr(NonisolatedAttr *attr); void visitCompletionHandlerAsyncAttr(CompletionHandlerAsyncAttr *attr); + + void visitPackageAttr(PackageAttr *attr); }; } // end anonymous namespace @@ -5638,6 +5640,29 @@ void AttributeChecker::visitCompletionHandlerAsyncAttr( AFD->getAsyncAlternative(); } +void AttributeChecker::visitPackageAttr(PackageAttr *attr) { + auto import = dyn_cast(D); + if (!import) + return; + + if (attr->getNumArguments() != 2) { + diagnose( + attr->getLocation(), diag::invalid_package_declaration, + attr->getNumArguments() > 2 ? "too many arguments":"too few arguments" + ); + } + + ModuleDecl *moduleDecl = import->getModule()->getTopLevelModule(); + if (!moduleDecl) + return; + + diagnose( + attr->getLocation(), diag::package_declaration, + moduleDecl->getABIName().str(), attr->getPackageDeclaration() + ); + // TODO +} + AbstractFunctionDecl *AsyncAlternativeRequest::evaluate( Evaluator &evaluator, AbstractFunctionDecl *attachedFunctionDecl) const { auto attr = attachedFunctionDecl->getAttrs() From ecc254b041d491697815d64cef3854a482e17ed0 Mon Sep 17 00:00:00 2001 From: stevapple Date: Tue, 10 Aug 2021 02:58:00 +0800 Subject: [PATCH 3/7] Wrap up GSoC --- README.md | 175 ++++++++++++++++++++--- include/swift/AST/DiagnosticsSema.def | 8 -- include/swift/Frontend/FrontendOptions.h | 3 +- lib/Sema/TypeCheckAttr.cpp | 26 +--- 4 files changed, 155 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index 62b33fff97829..6e4685ee4780c 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,164 @@ -# GSoC 2021: SwiftPM Support for Swift Packages +Swift logo -## Phase 1: Teaching the frontend to recognize package declaration syntax +# Swift Programming Language -### Determined tasks -- [x] The `@package` attribute; -- [x] The `ignore-package-declaration` flag; -- [x] Basic syntax checking for `@package`; -- [ ] The `emit-package-declaration` flag and output format; -- [ ] Teach the parser to read labels from external syntax file; -- [ ] Teach the type checker to check against external syntax file. +| | **Architecture** | **main** | **Package** | +|---|:---:|:---:|:---:| +| **macOS** | x86_64 |[![Build Status](https://ci.swift.org/job/oss-swift-incremental-RA-macos/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-incremental-RA-macos)|[![Build Status](https://ci.swift.org/job/oss-swift-package-macos/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-macos)| +| **Ubuntu 16.04** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-16_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-16_04)|[![Build Status](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-16_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-16_04)| +| **Ubuntu 18.04** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-18_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-18_04)|[![Build Status](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-18_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-18_04)| +| **Ubuntu 20.04** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-package-ubuntu-20_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-ubuntu-20_04)|[![Build Status](https://ci.swift.org/job/oss-swift-package-ubuntu-20_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-ubuntu-20_04)| +| **CentOS 8** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-package-centos-8/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-centos-8)|[![Build Status](https://ci.swift.org/job/oss-swift-package-centos-8/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-centos-8)| +| **Amazon Linux 2** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-package-amazon-linux-2/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-amazon-linux-2)|[![Build Status](https://ci.swift.org/job/oss-swift-package-amazon-linux-2/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-amazon-linux-2)| -### Future tasks +**Swift Community-Hosted CI Platforms** -- [ ] Integrated driver support (probably move to the second phase?); -- [ ] Test SourceKit; -- [ ] Write unit tests. +| **OS** | **Architecture** | **Build** | +|---|:---:|:---:| +|**[Ubuntu 16.04 ](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/ppc64le_ubuntu_16_04.json)** | PPC64LE |[![Build Status](https://ci-external.swift.org/job/oss-swift-5.1-RA-linux-ubuntu-16.04-ppc64le/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-5.1-RA-linux-ubuntu-16.04-ppc64le)| +|**[Ubuntu 18.04](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/aarch64_ubuntu_18.04_docker.json)** | AArch64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-ubuntu-18.04-aarch64/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-ubuntu-18.04-aarch64)| +|**[Ubuntu 20.04](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/aarch64_ubuntu_20.04_docker.json)** | AArch64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-ubuntu-20.04-aarch64/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-ubuntu-20.04-aarch64)| +|**[CentOS 8 ](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/aarch64_centos_8_docker.json)** | AArch64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-centos8-aarch64/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-centos8-aarch64)| +|**[Amazon Linux 2](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/aarch64_amazon_linux_2_docker.json)** | AArch64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-amazon-linux-2-aarch64/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-amazon-linux-2-aarch64)| +|**[Android](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_ubuntu_16_04_LTS_android.json)** | ARMv7 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-android/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-android)| +|**[Android](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_ubuntu_16_04_LTS_android.json)** | AArch64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-android-arm64/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-android-arm64)| +|**[Windows 2019 (VS 2017)](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_windows_2019.json)** | x86_64 | [![Build Status](https://ci-external.swift.org/job/oss-swift-windows-x86_64/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-windows-x86_64)| +|**[Windows 2019 (VS 2019)](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_windows_2019_VS2019.json)** | x86_64 | [![Build Status](https://ci-external.swift.org/job/oss-swift-windows-x86_64-vs2019/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-windows-x86_64-vs2019)| -### Needs further investigation +**Swift TensorFlow Community-Hosted CI Platforms** -- How to import the syntax from SwiftPM? -- How to generate the syntax definition file? -- How to typecheck the attribute in an "isolated" context? +| **OS** | **Architecture** | **Build** | +|---|:---:|:---:| +|**[Ubuntu 18.04](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_ubuntu_18_04_tensorflow.json)** | x86_64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-18.04-tensorflow/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-18.04-tensorflow)| +|**[macOS 10.13](https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/nodes/x86_64_macos_high_sierra_tensorflow.json)** | x86_64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-macOS-tensorflow/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-macOS-tensorflow)| -## Phase 2: Integrating the feature into the driver and package manager +## Welcome to Swift -TBD. +Swift is a high-performance system programming language. It has a clean +and modern syntax, offers seamless access to existing C and Objective-C code +and frameworks, and is memory safe by default. -## Notes from the discussions +Although inspired by Objective-C and many other languages, Swift is not itself a +C-derived language. As a complete and independent language, Swift packages core +features like flow control, data structures, and functions, with high-level +constructs like objects, protocols, closures, and generics. Swift embraces +modules, eliminating the need for headers and the code duplication they entail. -It seems best to provide package declaration syntax with a specific file from -SwiftPM, and we can expose it in some way that IDEs can also use. +To learn more about the programming language, visit [swift.org](https://swift.org/documentation/). + +- [Contributing to Swift](#contributing-to-swift) +- [Getting Started](#getting-started) + - [Swift Toolchains](#swift-toolchains) + - [Build Failures](#build-failures) +- [Learning More](#learning-more) + +## Contributing to Swift + +Contributions to Swift are welcomed and encouraged! Please see the +[Contributing to Swift guide](https://swift.org/contributing/). + +To be a truly great community, [Swift.org](https://swift.org/) needs to welcome +developers from all walks of life, with different backgrounds, and with a wide +range of experience. A diverse and friendly community will have more great +ideas, more unique perspectives, and produce more great code. We will work +diligently to make the Swift community welcoming to everyone. + +To give clarity of what is expected of our members, Swift has adopted the +code of conduct defined by the Contributor Covenant. This document is used +across many open source communities, and we think it articulates our values +well. For more, see the [Code of Conduct](https://swift.org/code-of-conduct/). + +## Getting Started + +If you are interested in: +- Contributing fixes and features to the compiler: See our + [How to Submit Your First Pull Request guide](/docs/HowToGuides/FirstPullRequest.md). +- Building the compiler as a one-off: See our [Getting Started guide][]. +- Building a toolchain as a one-off: Follow the [Getting Started guide][] + up until the "Building the project" section. After that, follow the + instructions in the [Swift Toolchains](#swift-toolchains) section below. + +We also have an [FAQ](/docs/HowToGuides/FAQ.md) that answers common questions. + +[Getting Started guide]: /docs/HowToGuides/GettingStarted.md + +### Swift Toolchains + +#### Building + +Swift toolchains are created using the script +[build-toolchain](https://github.com/apple/swift/blob/main/utils/build-toolchain). This +script is used by swift.org's CI to produce snapshots and can allow for one to +locally reproduce such builds for development or distribution purposes. A typical +invocation looks like the following: + +``` + $ ./swift/utils/build-toolchain $BUNDLE_PREFIX +``` + +where ``$BUNDLE_PREFIX`` is a string that will be prepended to the build +date to give the bundle identifier of the toolchain's ``Info.plist``. For +instance, if ``$BUNDLE_PREFIX`` was ``com.example``, the toolchain +produced will have the bundle identifier ``com.example.YYYYMMDD``. It +will be created in the directory you run the script with a filename +of the form: ``swift-LOCAL-YYYY-MM-DD-a-osx.tar.gz``. + +Beyond building the toolchain, ``build-toolchain`` also supports the +following (non-exhaustive) set of useful options:: + +- ``--dry-run``: Perform a dry run build. This is off by default. +- ``--test``: Test the toolchain after it has been compiled. This is off by default. +- ``--distcc``: Use distcc to speed up the build by distributing the c++ part of + the swift build. This is off by default. +- ``--sccache``: Use sccache to speed up subsequent builds of the compiler by + caching more c++ build artifacts. This is off by default. + +More options may be added over time. Please pass ``--help`` to +``build-toolchain`` to see the full set of options. + +#### Installing into Xcode + +On macOS if one wants to install such a toolchain into Xcode: + +1. Untar and copy the toolchain to one of `/Library/Developer/Toolchains/` or + `~/Library/Developer/Toolchains/`. E.x.: + +``` + $ sudo tar -xzf swift-LOCAL-YYYY-MM-DD-a-osx.tar.gz -C / + $ tar -xzf swift-LOCAL-YYYY-MM-DD-a-osx.tar.gz -C ~/ +``` + +The script also generates an archive containing debug symbols which +can be installed over the main archive allowing symbolication of any +compiler crashes. + +``` + $ sudo tar -xzf swift-LOCAL-YYYY-MM-DD-a-osx-symbols.tar.gz -C / + $ tar -xzf swift-LOCAL-YYYY-MM-DD-a-osx-symbols.tar.gz -C ~/ +``` + +2. Specify the local toolchain for Xcode's use via `Xcode->Toolchains`. + +### Build Failures + +Try the suggestions in +[Troubleshooting build issues](/docs/HowToGuides/GettingStarted.md#troubleshooting-build-issues). + +Make sure you are using the +[correct release](/docs/HowToGuides/GettingStarted.md#installing-dependencies) +of Xcode. + +If you have changed Xcode versions but still encounter errors that appear to +be related to the Xcode version, try passing `--clean` to `build-script`. + +When a new version of Xcode is released, you can update your build without +recompiling the entire project by passing `--reconfigure` to `build-script`. + +## Learning More + +Be sure to look at the [documentation index](/docs/README.md) for a bird's eye +view of the available documentation. In particular, the documents titled +[Debugging the Swift Compiler](docs/DebuggingTheCompiler.md) and +[Continuous Integration for Swift](docs/ContinuousIntegration.md) are very +helpful to understand before submitting your first PR. diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index 66a51ed4d1edd..f87e3aefa699f 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -5990,14 +5990,6 @@ ERROR(wrap_invalid_attr_added_by_access_note, none, "though it was " WHICH_ACCESS_NOTE(1), (DiagnosticInfo *, StringRef, StringRef, DescriptiveDeclKind)) -// Package diagnostics -NOTE(package_declaration, none, - "import '%0' from '%1'", - (StringRef, StringRef)) - -ERROR(invalid_package_declaration, none, - "%0", (StringRef)) - #undef WHICH_ACCESS_NOTE #define UNDEFINE_DIAGNOSTIC_MACROS diff --git a/include/swift/Frontend/FrontendOptions.h b/include/swift/Frontend/FrontendOptions.h index 9abf2cea86631..806852e63ad0f 100644 --- a/include/swift/Frontend/FrontendOptions.h +++ b/include/swift/Frontend/FrontendOptions.h @@ -424,8 +424,7 @@ class FrontendOptions { /// Whether to include symbols with SPI information in the symbol graph. bool IncludeSPISymbolsInSymbolGraph = false; - /// Package declarations. - /// TODO: Complete the description. + /// Whether to ignore package declarations. bool IgnorePackageDeclarations = false; private: diff --git a/lib/Sema/TypeCheckAttr.cpp b/lib/Sema/TypeCheckAttr.cpp index 3c5ba3280036c..7f587c9f853bb 100644 --- a/lib/Sema/TypeCheckAttr.cpp +++ b/lib/Sema/TypeCheckAttr.cpp @@ -115,6 +115,7 @@ class AttributeChecker : public AttributeVisitor { IGNORED_ATTR(ImplicitSelfCapture) IGNORED_ATTR(InheritActorContext) IGNORED_ATTR(Isolated) + IGNORED_ATTR(Package) #undef IGNORED_ATTR void visitAlignmentAttr(AlignmentAttr *attr) { @@ -265,8 +266,6 @@ class AttributeChecker : public AttributeVisitor { void visitReasyncAttr(ReasyncAttr *attr); void visitNonisolatedAttr(NonisolatedAttr *attr); void visitCompletionHandlerAsyncAttr(CompletionHandlerAsyncAttr *attr); - - void visitPackageAttr(PackageAttr *attr); }; } // end anonymous namespace @@ -5688,29 +5687,6 @@ void AttributeChecker::visitCompletionHandlerAsyncAttr( AFD->getAsyncAlternative(); } -void AttributeChecker::visitPackageAttr(PackageAttr *attr) { - auto import = dyn_cast(D); - if (!import) - return; - - if (attr->getNumArguments() != 2) { - diagnose( - attr->getLocation(), diag::invalid_package_declaration, - attr->getNumArguments() > 2 ? "too many arguments":"too few arguments" - ); - } - - ModuleDecl *moduleDecl = import->getModule()->getTopLevelModule(); - if (!moduleDecl) - return; - - diagnose( - attr->getLocation(), diag::package_declaration, - moduleDecl->getABIName().str(), attr->getPackageDeclaration() - ); - // TODO -} - AbstractFunctionDecl *AsyncAlternativeRequest::evaluate( Evaluator &evaluator, AbstractFunctionDecl *attachedFunctionDecl) const { auto attr = attachedFunctionDecl->getAttrs() From 574b1cbc7d7e430adf8c253a3c7ce61d30d5f4d2 Mon Sep 17 00:00:00 2001 From: stevapple Date: Sat, 14 Aug 2021 05:30:45 +0800 Subject: [PATCH 4/7] Fix spelling --- include/swift/AST/DiagnosticsParse.def | 2 +- include/swift/Basic/LangOptions.h | 4 ++-- include/swift/Parse/Parser.h | 2 +- lib/Frontend/CompilerInvocation.cpp | 2 +- lib/Parse/ParseDecl.cpp | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/swift/AST/DiagnosticsParse.def b/include/swift/AST/DiagnosticsParse.def index ed0fa188371ad..7365fa071307b 100644 --- a/include/swift/AST/DiagnosticsParse.def +++ b/include/swift/AST/DiagnosticsParse.def @@ -1861,7 +1861,7 @@ ERROR(expected_multiple_closures_block_rbrace,none, "expected '}' at the end of a trailing closures block", ()) // Package declaration errors -ERROR(package_declaration_not_allowed,none, +ERROR(package_declarations_not_allowed,none, "package declaration is not allowed", ()) #define UNDEFINE_DIAGNOSTIC_MACROS diff --git a/include/swift/Basic/LangOptions.h b/include/swift/Basic/LangOptions.h index 5a88df901ddaf..f6775f9250c0b 100644 --- a/include/swift/Basic/LangOptions.h +++ b/include/swift/Basic/LangOptions.h @@ -443,8 +443,8 @@ namespace swift { // FrontendOptions. bool AllowModuleWithCompilerErrors = false; - // Allow @package attribute in the file. - bool AllowPackageDeclaration = false; + // Allow @package attributes in the file. + bool AllowPackageDeclarations = false; // Ingore @package attributes in the file. bool IgnorePackageDeclarations = false; diff --git a/include/swift/Parse/Parser.h b/include/swift/Parse/Parser.h index c95363b696495..742afe073a853 100644 --- a/include/swift/Parse/Parser.h +++ b/include/swift/Parse/Parser.h @@ -193,7 +193,7 @@ class Parser { return Context.LangOpts.IgnorePackageDeclarations; } bool allowPackageDeclaration() const { - return Context.LangOpts.AllowPackageDeclaration || + return Context.LangOpts.AllowPackageDeclarations || Context.LangOpts.IgnorePackageDeclarations; } diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 8cee50ab592a7..39a6e69d36d68 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -775,7 +775,7 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args, } if (FrontendOpts.RequestedAction == FrontendOptions::ActionType::PrintPackageDeclarations) { - Opts.AllowPackageDeclaration = true; + Opts.AllowPackageDeclarations = true; } if (FrontendOpts.IgnorePackageDeclarations) { Opts.IgnorePackageDeclarations = true; diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 10511d9b18df7..c971c04727de5 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -2748,7 +2748,7 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc, case DAK_Package: { if (!allowPackageDeclaration()) { - diagnose(Loc, diag::package_declaration_not_allowed); + diagnose(Loc, diag::package_declarations_not_allowed); return false; } From 7cc970ed7bfe39360c29dbe363f3becfb5e8fb32 Mon Sep 17 00:00:00 2001 From: stevapple Date: Sat, 14 Aug 2021 05:31:22 +0800 Subject: [PATCH 5/7] Add packageparser to build-script --- utils/build-script | 2 + .../build_swift/driver_arguments.py | 6 + .../contents.xcworkspacedata | 3 + utils/build_swift/tests/expected_options.py | 5 + .../swift_build_support/products/__init__.py | 2 + .../products/packageparser.py | 107 ++++++++++++++++++ 6 files changed, 125 insertions(+) create mode 100644 utils/swift_build_support/swift_build_support/products/packageparser.py diff --git a/utils/build-script b/utils/build-script index e19967df1fa40..172e33e26fb84 100755 --- a/utils/build-script +++ b/utils/build-script @@ -944,6 +944,8 @@ class BuildScriptInvocation(object): product_classes.append(products.SwiftInspect) if self.args.tsan_libdispatch_test: product_classes.append(products.TSanLibDispatch) + if self.args.build_packageparser: + product_classes.append(products.PackageSyntaxParser) # Keep SwiftDriver at last. # swift-driver's integration with the build scripts is not fully diff --git a/utils/build_swift/build_swift/driver_arguments.py b/utils/build_swift/build_swift/driver_arguments.py index 850c30dce3d86..2c2bb539bf7a0 100644 --- a/utils/build_swift/build_swift/driver_arguments.py +++ b/utils/build_swift/build_swift/driver_arguments.py @@ -193,6 +193,7 @@ def _apply_default_arguments(args): args.test_swiftformat = False args.test_swiftevolve = False args.test_toolchainbenchmarks = False + args.test_packageparser = False # --test implies --test-early-swift-driver # (unless explicitly skipped with `--skip-test-early-swift-driver`) @@ -617,6 +618,9 @@ def create_argument_parser(): option(['--swiftevolve'], toggle_true('build_swiftevolve'), help='build the swift-evolve tool') + option(['--package-parser'], toggle_true('build_packageparser'), + help='build package-syntax-parser') + option(['--swift-driver'], toggle_true('build_swift_driver'), help='build swift-driver') @@ -1097,6 +1101,8 @@ def create_argument_parser(): option('--skip-test-swift-inspect', toggle_false('test_swift_inspect'), help='skip testing swift_inspect') + option('--skip-test-package-parser', toggle_false('test_packageparser'), + help='skip testing package-syntax-parser') # ------------------------------------------------------------------------- in_group('Build settings specific for LLVM') diff --git a/utils/build_swift/resources/SwiftPM-Unified-Build.xcworkspace/contents.xcworkspacedata b/utils/build_swift/resources/SwiftPM-Unified-Build.xcworkspace/contents.xcworkspacedata index 92ad6dd28df5b..10f76c0b65b2a 100644 --- a/utils/build_swift/resources/SwiftPM-Unified-Build.xcworkspace/contents.xcworkspacedata +++ b/utils/build_swift/resources/SwiftPM-Unified-Build.xcworkspace/contents.xcworkspacedata @@ -10,6 +10,9 @@ + + diff --git a/utils/build_swift/tests/expected_options.py b/utils/build_swift/tests/expected_options.py index bc0041beea192..38288e0e5bb82 100644 --- a/utils/build_swift/tests/expected_options.py +++ b/utils/build_swift/tests/expected_options.py @@ -99,6 +99,7 @@ 'test_indexstoredb_sanitize_all': False, 'test_sourcekitlsp_sanitize_all': False, 'build_sourcekitlsp': False, + 'build_packageparser': False, 'install_swiftpm': False, 'install_swiftsyntax': False, 'install_swift_driver': False, @@ -107,6 +108,7 @@ 'install_sourcekitlsp': False, 'install_skstresstester': False, 'install_swiftevolve': False, + 'install_packageparser': False, 'build_toolchainbenchmarks': False, 'build_tvos': True, 'build_tvos_device': False, @@ -257,6 +259,7 @@ 'test_swiftformat': False, 'test_swiftevolve': False, 'test_toolchainbenchmarks': False, + 'test_packageparser': False, 'tvos': False, 'tvos_all': False, 'validation_test': None, @@ -498,6 +501,7 @@ class BuildScriptImplOption(_BaseOption): SetTrueOption('--skstresstester', dest='build_skstresstester'), SetTrueOption('--swiftformat', dest='build_swiftformat'), SetTrueOption('--swiftevolve', dest='build_swiftevolve'), + SetTrueOption('--package-parser', dest='build_packageparser'), SetTrueOption('-B', dest='benchmark'), SetTrueOption('-S', dest='skip_build'), SetTrueOption('-b', dest='build_llbuild'), @@ -630,6 +634,7 @@ class BuildScriptImplOption(_BaseOption): DisableOption('--skip-test-skstresstester', dest='test_skstresstester'), DisableOption('--skip-test-swiftformat', dest='test_swiftformat'), DisableOption('--skip-test-swiftevolve', dest='test_swiftevolve'), + DisableOption('--skip-test-package-parser', dest='test_packageparser'), DisableOption('--skip-test-toolchain-benchmarks', dest='test_toolchainbenchmarks'), DisableOption('--skip-test-swift-inspect', diff --git a/utils/swift_build_support/swift_build_support/products/__init__.py b/utils/swift_build_support/swift_build_support/products/__init__.py index c13c0dc4b5491..00cf5d6dc7309 100644 --- a/utils/swift_build_support/swift_build_support/products/__init__.py +++ b/utils/swift_build_support/swift_build_support/products/__init__.py @@ -34,6 +34,7 @@ from .swiftsyntax import SwiftSyntax from .tsan_libdispatch import TSanLibDispatch from .xctest import XCTest +from .packageparser import PackageSyntaxParser __all__ = [ 'CMark', @@ -61,4 +62,5 @@ 'SourceKitLSP', 'Benchmarks', 'TSanLibDispatch', + 'PackageSyntaxParser', ] diff --git a/utils/swift_build_support/swift_build_support/products/packageparser.py b/utils/swift_build_support/swift_build_support/products/packageparser.py new file mode 100644 index 0000000000000..a377f2a59bdb2 --- /dev/null +++ b/utils/swift_build_support/swift_build_support/products/packageparser.py @@ -0,0 +1,107 @@ +# swift_build_support/products/packageparser.py -----------------*- python -*- +# +# This source file is part of the Swift.org open source project +# +# Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors +# Licensed under Apache License v2.0 with Runtime Library Exception +# +# See https://swift.org/LICENSE.txt for license information +# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +# +# ---------------------------------------------------------------------------- + +import os + +from build_swift.build_swift.constants import MULTIROOT_DATA_FILE_PATH + +from . import cmark +from . import foundation +from . import libcxx +from . import libdispatch +from . import libicu +from . import llbuild +from . import llvm +from . import product +from . import swift +from . import swiftpm +from . import swiftsyntax +from . import xctest +from .. import shell + + +class PackageSyntaxParser(product.Product): + @classmethod + def product_source_name(cls): + """product_source_name() -> str + + The name of the source code directory of this product. + """ + return "package-syntax-parser" + + @classmethod + def is_build_script_impl_product(cls): + return False + + @classmethod + def is_before_build_script_impl_product(cls): + return False + + @classmethod + def is_swiftpm_unified_build_product(cls): + return True + + def run_build_script_helper(self, action, host_target, additional_params=[]): + script_path = os.path.join( + self.source_dir, 'build-script-helper.py') + + configuration = 'release' if self.is_release() else 'debug' + + helper_cmd = [ + script_path, + action, + '--toolchain', self.install_toolchain_path(host_target), + '--configuration', configuration, + '--build-path', self.build_dir, + '--multiroot-data-file', MULTIROOT_DATA_FILE_PATH, + # There might have been a Package.resolved created by other builds + # or by the package being opened using Xcode. Discard that and + # reset the dependencies to be local. + '--update' + ] + if self.args.verbose_build: + helper_cmd.append('--verbose') + helper_cmd.extend(additional_params) + + shell.call(helper_cmd) + + def should_build(self, host_target): + return True + + def build(self, host_target): + self.run_build_script_helper('build', host_target) + + def should_test(self, host_target): + return self.args.test_packageparser + + def test(self, host_target): + self.run_build_script_helper('test', host_target) + + def should_install(self, host_target): + return self.args.install_swiftpm + + def install(self, host_target): + self.run_build_script_helper('install', host_target) + + @classmethod + def get_dependencies(cls): + return [cmark.CMark, + llvm.LLVM, + libcxx.LibCXX, + libicu.LibICU, + swift.Swift, + libdispatch.LibDispatch, + foundation.Foundation, + xctest.XCTest, + llbuild.LLBuild, + swiftpm.SwiftPM, + swiftsyntax.SwiftSyntax] From 2ade2bf600978782a346e0312d93b715047a91ec Mon Sep 17 00:00:00 2001 From: stevapple Date: Tue, 17 Aug 2021 00:48:25 +0800 Subject: [PATCH 6/7] Update checkout config --- .../update-checkout-config.json | 53 +++++++++++++++---- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/utils/update_checkout/update-checkout-config.json b/utils/update_checkout/update-checkout-config.json index 4ce7f2850f64b..68ac714c9bc63 100644 --- a/utils/update_checkout/update-checkout-config.json +++ b/utils/update_checkout/update-checkout-config.json @@ -3,7 +3,7 @@ "https-clone-pattern": "https://github.com/%s.git", "repos" : { "swift": { - "remote": { "id": "apple/swift" } }, + "remote": { "id": "stevapple/swift" } }, "cmark": { "remote": { "id": "apple/swift-cmark" } }, "llbuild": { @@ -17,13 +17,13 @@ "swift-crypto": { "remote": { "id": "apple/swift-crypto" } }, "swift-driver": { - "remote": { "id": "apple/swift-driver" } }, + "remote": { "id": "stevapple/swift-driver" } }, "swift-numerics": { - "remote": { "id": "apple/swift-numerics" } }, + "remote": { "id": "apple/swift-numerics" } }, "swift-tools-support-core": { "remote": { "id": "apple/swift-tools-support-core" } }, "swiftpm": { - "remote": { "id": "apple/swift-package-manager" } }, + "remote": { "id": "stevapple/swift-package-manager" } }, "swift-syntax": { "remote": { "id": "apple/swift-syntax" } }, "swift-system": { @@ -53,18 +53,53 @@ "remote": { "id": "KitWare/CMake" }, "platforms": [ "Linux" ] }, - "indexstore-db": { + "indexstore-db": { "remote": { "id": "apple/indexstore-db" } }, "sourcekit-lsp": { "remote": { "id": "apple/sourcekit-lsp" } }, "swift-format": { "remote": { "id": "apple/swift-format" } }, "llvm-project": { - "remote": { "id": "apple/llvm-project" } } + "remote": { "id": "apple/llvm-project" } }, + "package-syntax-parser": { + "remote": { "id": "stevapple/package-syntax-parser" } } }, - "default-branch-scheme": "main", + "default-branch-scheme": "gsoc", "branch-schemes": { - "main": { + "gsoc": { + "aliases": ["gsoc-2021", "package-syntax", "gsoc"], + "repos": { + "llvm-project": "swift/main", + "swift": "gsoc-2021", + "cmark": "main", + "llbuild": "main", + "swift-tools-support-core": "main", + "swiftpm": "gsoc-2021", + "swift-argument-parser": "0.4.3", + "swift-atomics": "0.0.3", + "swift-collections": "0.0.4", + "swift-crypto": "1.1.5", + "swift-driver": "gsoc-2021", + "swift-numerics": "0.1.0", + "swift-syntax": "main", + "swift-system": "0.0.2", + "swift-stress-tester": "main", + "swift-corelibs-xctest": "main", + "swift-corelibs-foundation": "main", + "swift-corelibs-libdispatch": "main", + "swift-integration-tests": "main", + "swift-xcode-playground-support": "main", + "ninja": "release", + "icu": "release-65-1", + "yams": "4.0.2", + "cmake": "v3.19.6", + "indexstore-db": "main", + "sourcekit-lsp": "main", + "swift-format": "main", + "package-syntax-parser": "main" + } + }, + "main": { "aliases": ["master", "swift/main", "main"], "repos": { "llvm-project": "swift/main", @@ -96,7 +131,7 @@ "swift-format": "main" } }, - "release/5.5": { + "release/5.5": { "aliases": ["release/5.5", "swift/release/5.5"], "repos": { "llvm-project": "swift/release/5.5", From 0db861eed21f586ca1eb8df192beee0783683f06 Mon Sep 17 00:00:00 2001 From: stevapple Date: Wed, 5 Jan 2022 02:14:00 +0800 Subject: [PATCH 7/7] Fix checkout schemes --- .../update-checkout-config.json | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/utils/update_checkout/update-checkout-config.json b/utils/update_checkout/update-checkout-config.json index 68ac714c9bc63..449f230eefd62 100644 --- a/utils/update_checkout/update-checkout-config.json +++ b/utils/update_checkout/update-checkout-config.json @@ -69,11 +69,11 @@ "gsoc": { "aliases": ["gsoc-2021", "package-syntax", "gsoc"], "repos": { - "llvm-project": "swift/main", + "llvm-project": "swift-DEVELOPMENT-SNAPSHOT-2021-08-14-a", "swift": "gsoc-2021", - "cmark": "main", - "llbuild": "main", - "swift-tools-support-core": "main", + "cmark": "swift-DEVELOPMENT-SNAPSHOT-2021-08-14-a", + "llbuild": "swift-DEVELOPMENT-SNAPSHOT-2021-08-14-a", + "swift-tools-support-core": "swift-DEVELOPMENT-SNAPSHOT-2021-08-14-a", "swiftpm": "gsoc-2021", "swift-argument-parser": "0.4.3", "swift-atomics": "0.0.3", @@ -81,21 +81,21 @@ "swift-crypto": "1.1.5", "swift-driver": "gsoc-2021", "swift-numerics": "0.1.0", - "swift-syntax": "main", + "swift-syntax": "swift-DEVELOPMENT-SNAPSHOT-2021-07-30-a", "swift-system": "0.0.2", - "swift-stress-tester": "main", - "swift-corelibs-xctest": "main", - "swift-corelibs-foundation": "main", - "swift-corelibs-libdispatch": "main", - "swift-integration-tests": "main", - "swift-xcode-playground-support": "main", - "ninja": "release", + "swift-stress-tester": "swift-DEVELOPMENT-SNAPSHOT-2021-08-14-a", + "swift-corelibs-xctest": "swift-DEVELOPMENT-SNAPSHOT-2021-08-14-a", + "swift-corelibs-fswoundation": "swift-DEVELOPMENT-SNAPSHOT-2021-08-14-a", + "swift-corelibs-libdispatch": "swift-DEVELOPMENT-SNAPSHOT-2021-08-14-a", + "swift-integration-tests": "swift-DEVELOPMENT-SNAPSHOT-2021-08-14-a", + "swift-xcode-playground-support": "swift-DEVELOPMENT-SNAPSHOT-2021-08-14-a", + "ninja": "v1.10.2", "icu": "release-65-1", "yams": "4.0.2", "cmake": "v3.19.6", - "indexstore-db": "main", - "sourcekit-lsp": "main", - "swift-format": "main", + "indexstore-db": "swift-DEVELOPMENT-SNAPSHOT-2021-08-14-a", + "sourcekit-lsp": "swift-DEVELOPMENT-SNAPSHOT-2021-08-14-a", + "swift-format": "e3a4b21152e07873b647831c8cc019d2b44c3eaa", "package-syntax-parser": "main" } },