المساهمة في Swift



تبدو مألوفة؟



في كل مرة حاولت فيها إعلان إغلاق اختياري @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 :



  1. bugs.swift.org.
  2. Swift.
  3. .
  4. .
  5. .
  6. .
  7. .
  8. .


.



bugs.swift.org



JIRA — , Issues .



Starter Bug- — , Swift. , .



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 .



, , . :



  1. , .
  2. ( ), .
  3. , .


.





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




Swift , . lit.py, cmake. .



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.





Swift , . , ++ . , , .





, .







opensource- Swift , .



, , . Starter Task- Swift!








All Articles