تبدو مألوفة؟
في كل مرة حاولت فيها إعلان إغلاق اختياري @escaping
في Swift ، يلعن المترجم وكتب خطأً غير مفهوم @escaping attribute only applies to function types
. لم يعجبني وقررت إصلاحه . الآن سيكتب مترجم Swift 5.3 بدلاً من هذا الخطأ Closure is already escaping in optional type argument
.
واليوم سنكتشف كيفية المساهمة في تطوير لغة Swift.
لاجل ماذا
Swift — opensource-, , — . "contributed to Apple".
Swift macOS, Linux Windows, 15-70 GB Swift ( ).
Swift ++, , -, .
9 :
- bugs.swift.org.
- Swift.
- .
- .
- .
- .
- .
- .
.
bugs.swift.org
JIRA — , Issues .
Swift
Readme . , macOS, Linux Windows Swift .
brew install cmake ninja
brew bundle
mkdir swift-source
cd swift-source
git clone https://github.com/apple/swift.git #
./swift/utils/update-checkout --clone
environment variable .
export SWIFT="~/swift-source"
export LLVM_SOURCE_ROOT="~/swift-source/llvm"
Swift — ninja Xcode.
Xcode , iOS IDE.
Ninja — C++ -, Xcode , IDE — Xcode. Swift ninja.
build-script
— , LLDB Swift, SPM, ..
:
cd swift
ninja:
utils/build-script --release-debuginfo #
- , :
utils/build-script --release-debuginfo --debug-swift # ,
utils/build-script --release-debuginfo --debug-swift-stdlib # std ,
Mac Pro, Swift :
: , + (~70 GB)
utils/build-script --debug
environment :
export SWIFT_BUILD_DIR="~/swift-source/build/Ninja-DebugAssert/swift-macosx-x86_64"
, ninja:
cd ${SWIFT_BUILD_DIR}
ninja swift
- , ninja swift
.
Xcode
--xcode
.
environment :
export XCODE_BUILD_DIR="~/swift-source/build/Xcode-DebugAssert/swift-macosx-x86_64"
.xcodeproj ,
open ${XCODE_BUILD_DIR}/Swift.xcodeproj
, Xcode .
swift Run. Swift, Xcode.
Xcode , .
swift, , .
P.S , , — forums.swift.org. .
— , .
, . , , . , Swift, , , , .
, , , Swift . Swift , , , , ..
Contributing to open source Swift by Jesse Squires
1) ( lib/Parse)
— AST ( ). — , . , , AST.
, / ..
2) (lib/Sema)
AST AST. .
3) Clang (lib/ClangImporter)
Clang C Objective-C API Swift API.
4) SIL (lib/SILGen)
Swift Intermediate Language (SIL) — , Swift . AST "" SIL.
5) SIL (lib/SILOptimizer/Mandatory)
, , . "" SIL.
6) SIL (lib/SILOptimizer)
, , ARC.
7) LLVM IR (lib/IRGen)
IR (Intermediate Representation) SIL LLVM IR, LLVM .
, , . :
- , .
- ( ), .
- , .
.
Swift :
- TDD — , , , ( );
- , Sema… TypeCheck… .
, .
Xcode Swift. , DiagnosticsSema.def
escaping_non_function_parameter
, , , NOTE
, ERROR
.
// AST/DiagnosticsSema.def
ERROR(escaping_optional_type_argument, none,
"closure is already escaping in optional type argument", ())
. , , .
// test/attr/attr_escaping.swift
func misuseEscaping(opt a: @escaping ((Int) -> Int)?) {} // expected-error{{closure is already escaping in optional type argument}} {{28-38=}}
func misuseEscaping(_ a: (@escaping (Int) -> Int)?) {} // expected-error{{closure is already escaping in optional type argument}} {{27-36=}}
func misuseEscaping(nest a: (((@escaping (Int) -> Int))?)) {} // expected-error{{closure is already escaping in optional type argument}} {{32-41=}}
func misuseEscaping(iuo a: (@escaping (Int) -> Int)!) {} // expected-error{{closure is already escaping in optional type argument}} {{29-38=}}
TypeCheckType.cpp
, , , . , . , . , . , , , .
// *TypeCheckType.cpp*
const auto diagnoseInvalidAttr = [&](TypeAttrKind kind) {
if (kind == TAK_escaping) {
Type optionalObjectType = ty->getOptionalObjectType();
if (optionalObjectType && optionalObjectType->is<AnyFunctionType>()) {
return diagnoseInvalid(repr, attrs.getLoc(kind),
diag::escaping_optional_type_argument);
}
}
return diagnoseInvalid(repr, attrs.getLoc(kind),
diag::attribute_requires_function_type,
TypeAttributes::getAttrName(kind));
};
TypeCheckType.cpp
: if-, .
: C++ , clang-format, .
$SWIFT/clang/tools/clang-format/git-clang-format --force
lit.py, cheatsheet, .
#
${LLVM_SOURCE_ROOT}/utils/lit/lit.py ${SWIFT_BUILD_DIR}/test-macosx-x86_64/
#
${LLVM_SOURCE_ROOT}/utils/lit/lit.py -sv ${SWIFT_BUILD_DIR}/test-macosx-x86_64/
#
${LLVM_SOURCE_ROOT}/utils/lit/lit.py -a ${SWIFT_BUILD_DIR}/test-macosx-x86_64/attr/attr_escaping.swift}
#
${LLVM_SOURCE_ROOT}/utils/lit/lit.py ${SWIFT_BUILD_DIR}/validation-test-macosx-x86_64/
# ? - ?
${LLVM_SOURCE_ROOT}/utils/lit/lit.py ${SWIFT_BUILD_DIR}/test-macosx-x86_64/ --filter=<REGEX>
: lit --filter
.
, , .
, squash , . , . : fix-it-for-removing-escaping-from-optional-closure-parameter
.
, .
opensource- Swift , .
, , . Starter Task- Swift!
- Swift .
- swift.org.
- Swift.
- Swift Weekly Brief, Swift, Starter Bug.
- , , : , , .
- Ayaka Nonaka , Swift, .
- Jesse Squires , , .
- PSPDFKit Swift.
- LLVM.