diff --git a/apinotes/AVFoundation.apinotes b/apinotes/AVFoundation.apinotes index 135dfc521a715..773e1a5827365 100644 --- a/apinotes/AVFoundation.apinotes +++ b/apinotes/AVFoundation.apinotes @@ -14,12 +14,6 @@ Classes: - Selector: 'appendSampleBuffer:' SwiftName: append(_:) MethodKind: Instance - - Selector: 'appendPixelBuffer:withPresentationTime:' - SwiftName: append(_:withPresentationTime:) - MethodKind: Instance - - Selector: 'appendTimedMetadataGroup:' - SwiftName: append(_:) - MethodKind: Instance - Name: AVAssetWriterInputPixelBufferAdaptor Methods: - Selector: 'appendPixelBuffer:withPresentationTime:' @@ -98,7 +92,7 @@ Classes: - Name: AVVideoComposition Methods: - Selector: 'videoCompositionWithPropertiesOfAsset:' - SwiftName: init(withPropertiesOf:) + SwiftName: init(propertiesOf:) MethodKind: Instance - Selector: 'videoCompositionWithAsset:applyingCIFiltersWithHandler:' SwiftName: init(asset:filterApplier:) @@ -137,7 +131,6 @@ Classes: - Selector: 'initWithURL:fileType:error:' SwiftName: init(outputURL:fileType:) MethodKind: Instance - Availability: nonswift - Selector: 'canApplyOutputSettings:forMediaType:' SwiftName: canApply(outputSettings:forMediaType:) MethodKind: Instance diff --git a/apinotes/AppKit.apinotes b/apinotes/AppKit.apinotes index 2ae3b8ff84048..66d182838dd6d 100644 --- a/apinotes/AppKit.apinotes +++ b/apinotes/AppKit.apinotes @@ -1,6 +1,22 @@ --- Name: AppKit Classes: +- Name: NSButton + Methods: + - Selector: 'mouseEntered:' + SwiftName: mouseEntered(with:) + MethodKind: Instance + - Selector: 'mouseExited:' + SwiftName: mouseExited(with:) + MethodKind: Instance +- Name: NSButtonCell + Methods: + - Selector: 'mouseEntered:' + SwiftName: mouseEntered(with:) + MethodKind: Instance + - Selector: 'mouseExited:' + SwiftName: mouseExited(with:) + MethodKind: Instance - Name: NSCell Methods: - Selector: 'initImageCell:' @@ -15,6 +31,14 @@ Classes: - Selector: 'stopTracking:at:inView:mouseIsUp:' SwiftName: stopTracking(last:current:in:mouseIsUp:) MethodKind: Instance + - Selector: 'trackMouse:inRect:ofView:untilMouseUp:' + SwiftName: trackMouse(with:in:of:untilMouseUp:) + MethodKind: Instance +- Name: NSClipView + Methods: + - Selector: 'autoscroll:' + SwiftName: autoscroll(with:) + MethodKind: Instance - Name: NSControl Methods: - Selector: 'initWithFrame:' @@ -26,11 +50,20 @@ Classes: - Selector: 'drawCellInside:' SwiftName: drawCellInside(_:) MethodKind: Instance + - Selector: 'mouseDown:' + SwiftName: mouseDown(with:) + MethodKind: Instance - Name: NSCursor Methods: - Selector: 'initWithImage:hotSpot:' MethodKind: Instance DesignatedInit: true + - Selector: 'mouseEntered:' + SwiftName: mouseEntered(with:) + MethodKind: Instance + - Selector: 'mouseExited:' + SwiftName: mouseExited(with:) + MethodKind: Instance - Name: NSDocument Methods: - Selector: init @@ -77,6 +110,47 @@ Classes: - Selector: 'initTextCell:' MethodKind: Instance DesignatedInit: true +- Name: NSGestureRecognizer + Methods: + - Selector: 'mouseDown:' + SwiftName: mouseDown(with:) + MethodKind: Instance + - Selector: 'rightMouseDown:' + SwiftName: rightMouseDown(with:) + MethodKind: Instance + - Selector: 'otherMouseDown:' + SwiftName: otherMouseDown(with:) + MethodKind: Instance + - Selector: 'mouseUp:' + SwiftName: mouseUp(with:) + MethodKind: Instance + - Selector: 'rightMouseUp:' + SwiftName: rightMouseUp(with:) + MethodKind: Instance + - Selector: 'otherMouseUp:' + SwiftName: otherMouseUp(with:) + MethodKind: Instance + - Selector: 'mouseDragged:' + SwiftName: mouseDragged(with:) + MethodKind: Instance + - Selector: 'rightMouseDragged:' + SwiftName: rightMouseDragged(with:) + MethodKind: Instance + - Selector: 'otherMouseDragged:' + SwiftName: otherMouseDragged(with:) + MethodKind: Instance + - Selector: 'keyDown:' + SwiftName: keyDown(with:) + MethodKind: Instance + - Selector: 'keyUp:' + SwiftName: keyUp(with:) + MethodKind: Instance + - Selector: 'flagsChanged:' + SwiftName: flagsChanged(with:) + MethodKind: Instance + - Selector: 'tabletPoint:' + SwiftName: tabletPoint(with:) + MethodKind: Instance - Name: NSGradient Methods: - Selector: 'initWithColors:atLocations:colorSpace:' @@ -146,6 +220,15 @@ Classes: - Selector: 'sortUsingFunction:context:' SwiftName: sort(using:context:) MethodKind: Instance + - Selector: 'mouseDown:' + SwiftName: mouseDown(with:) + MethodKind: Instance + - Selector: 'performKeyEquivalent:' + SwiftName: performKeyEquivalent(with:) + MethodKind: Instance + - Selector: 'acceptsFirstMouse:' + SwiftName: acceptsFirstMouse(for:) + MethodKind: Instance - Name: NSMenu Methods: - Selector: 'initWithTitle:' @@ -163,6 +246,12 @@ Classes: - Selector: 'removeItem:' SwiftName: removeItem(_:) MethodKind: Instance + - Selector: 'performKeyEquivalent:' + SwiftName: performKeyEquivalent(with:) + MethodKind: Instance + - Selector: 'helpRequested:' + SwiftName: helpRequested(with:) + MethodKind: Instance Properties: - Name: itemArray SwiftName: items @@ -171,6 +260,14 @@ Classes: - Selector: 'initWithFrame:' MethodKind: Instance DesignatedInit: true +- Name: NSPathCell + Methods: + - Selector: 'mouseEntered:withFrame:inView:' + SwiftName: mouseEntered(with:frame:in:) + MethodKind: Instance + - Selector: 'mouseExited:withFrame:inView:' + SwiftName: mouseExited(with:frame:in:) + MethodKind: Instance - Name: NSPopUpButtonCell Methods: - Selector: 'initTextCell:pullsDown:' @@ -189,6 +286,9 @@ Classes: - Selector: 'initWithRulerView:markerLocation:image:imageOrigin:' MethodKind: Instance DesignatedInit: true + - Selector: 'trackMouse:adding:' + SwiftName: trackMouse(with:adding:) + MethodKind: Instance - Name: NSRulerView Methods: - Selector: 'initWithScrollView:orientation:' @@ -248,6 +348,9 @@ Classes: - Selector: 'handleTextCheckingResults:forRange:types:options:orthography:wordCount:' SwiftName: handleTextCheckingResults(_:forRange:types:options:orthography:wordCount:) MethodKind: Instance + - Selector: 'rulerView:handleMouseDown:' + SwiftName: rulerView(_:handleMouseDownWith:) + MethodKind: Instance - Name: NSUserDefaultsController Methods: - Selector: 'initWithDefaults:initialValues:' @@ -315,6 +418,9 @@ Classes: - Selector: 'handleCloseScriptCommand:' SwiftName: handleClose(_:) MethodKind: Instance + - Selector: 'keyDown:' + SwiftName: keyDown(with:) + MethodKind: Instance Properties: - Name: isFlushWindowDisabled SwiftName: isFlushingDisabled @@ -443,118 +549,83 @@ Classes: SwiftName: noteHeightOfRowsWithIndexesChanged(_:inColumn:) MethodKind: Instance - Name: NSColor + Properties: + - Name: controlShadowColor + SwiftName: controlShadowColor + - Name: controlDarkShadowColor + SwiftName: controlDarkShadowColor + - Name: controlColor + SwiftName: controlColor + - Name: controlHighlightColor + SwiftName: controlHighlightColor + - Name: controlLightHighlightColor + SwiftName: controlLightHighlightColor + - Name: controlTextColor + SwiftName: controlTextColor + - Name: controlBackgroundColor + SwiftName: controlBackgroundColor + - Name: selectedControlColor + SwiftName: selectedControlColor + - Name: secondarySelectedControlColor + SwiftName: secondarySelectedControlColor + - Name: selectedControlTextColor + SwiftName: selectedControlTextColor + - Name: disabledControlTextColor + SwiftName: disabledControlTextColor + - Name: textColor + SwiftName: textColor + - Name: textBackgroundColor + SwiftName: textBackgroundColor + - Name: selectedTextColor + SwiftName: selectedTextColor + - Name: selectedTextBackgroundColor + SwiftName: selectedTextBackgroundColor + - Name: gridColor + SwiftName: gridColor + - Name: keyboardFocusIndicatorColor + SwiftName: keyboardFocusIndicatorColor + - Name: windowBackgroundColor + SwiftName: windowBackgroundColor + - Name: underPageBackgroundColor + SwiftName: underPageBackgroundColor + - Name: labelColor + SwiftName: labelColor + - Name: secondaryLabelColor + SwiftName: secondaryLabelColor + - Name: tertiaryLabelColor + SwiftName: tertiaryLabelColor + - Name: quaternaryLabelColor + SwiftName: quaternaryLabelColor + - Name: scrollBarColor + SwiftName: scrollBarColor + - Name: knobColor + SwiftName: knobColor + - Name: selectedKnobColor + SwiftName: selectedKnobColor + - Name: windowFrameColor + SwiftName: windowFrameColor + - Name: windowFrameTextColor + SwiftName: windowFrameTextColor + - Name: selectedMenuItemColor + SwiftName: selectedMenuItemColor + - Name: selectedMenuItemTextColor + SwiftName: selectedMenuItemTextColor + - Name: highlightColor + SwiftName: highlightColor + - Name: shadowColor + SwiftName: shadowColor + - Name: headerColor + SwiftName: headerColor + - Name: headerTextColor + SwiftName: headerTextColor + - Name: alternateSelectedControlColor + SwiftName: alternateSelectedControlColor + - Name: alternateSelectedControlTextColor + SwiftName: alternateSelectedControlTextColor Methods: - Selector: 'colorWithSRGBRed:green:blue:alpha:' SwiftName: init(sRGBRed:green:blue:alpha:) MethodKind: Instance - - Selector: controlShadowColor - SwiftName: controlShadowColor() - MethodKind: Class - - Selector: controlDarkShadowColor - SwiftName: controlDarkShadowColor() - MethodKind: Class - - Selector: controlColor - SwiftName: controlColor() - MethodKind: Class - - Selector: controlHighlightColor - SwiftName: controlHighlightColor() - MethodKind: Class - - Selector: controlLightHighlightColor - SwiftName: controlLightHighlightColor() - MethodKind: Class - - Selector: controlTextColor - SwiftName: controlTextColor() - MethodKind: Class - - Selector: controlBackgroundColor - SwiftName: controlBackgroundColor() - MethodKind: Class - - Selector: selectedControlColor - SwiftName: selectedControlColor() - MethodKind: Class - - Selector: secondarySelectedControlColor - SwiftName: secondarySelectedControlColor() - MethodKind: Class - - Selector: selectedControlTextColor - SwiftName: selectedControlTextColor() - MethodKind: Class - - Selector: disabledControlTextColor - SwiftName: disabledControlTextColor() - MethodKind: Class - - Selector: textColor - SwiftName: textColor() - MethodKind: Class - - Selector: textBackgroundColor - SwiftName: textBackgroundColor() - MethodKind: Class - - Selector: selectedTextColor - SwiftName: selectedTextColor() - MethodKind: Class - - Selector: selectedTextBackgroundColor - SwiftName: selectedTextBackgroundColor() - MethodKind: Class - - Selector: gridColor - SwiftName: gridColor() - MethodKind: Class - - Selector: keyboardFocusIndicatorColor - SwiftName: keyboardFocusIndicatorColor() - MethodKind: Class - - Selector: windowBackgroundColor - SwiftName: windowBackgroundColor() - MethodKind: Class - - Selector: underPageBackgroundColor - SwiftName: underPageBackgroundColor() - MethodKind: Class - - Selector: labelColor - SwiftName: labelColor() - MethodKind: Class - - Selector: secondaryLabelColor - SwiftName: secondaryLabelColor() - MethodKind: Class - - Selector: tertiaryLabelColor - SwiftName: tertiaryLabelColor() - MethodKind: Class - - Selector: quaternaryLabelColor - SwiftName: quaternaryLabelColor() - MethodKind: Class - - Selector: scrollBarColor - SwiftName: scrollBarColor() - MethodKind: Class - - Selector: knobColor - SwiftName: knobColor() - MethodKind: Class - - Selector: selectedKnobColor - SwiftName: selectedKnobColor() - MethodKind: Class - - Selector: windowFrameColor - SwiftName: windowFrameColor() - MethodKind: Class - - Selector: windowFrameTextColor - SwiftName: windowFrameTextColor() - MethodKind: Class - - Selector: selectedMenuItemColor - SwiftName: selectedMenuItemColor() - MethodKind: Class - - Selector: selectedMenuItemTextColor - SwiftName: selectedMenuItemTextColor() - MethodKind: Class - - Selector: highlightColor - SwiftName: highlightColor() - MethodKind: Class - - Selector: shadowColor - SwiftName: shadowColor() - MethodKind: Class - - Selector: headerColor - SwiftName: headerColor() - MethodKind: Class - - Selector: headerTextColor - SwiftName: headerTextColor() - MethodKind: Class - - Selector: alternateSelectedControlColor - SwiftName: alternateSelectedControlColor() - MethodKind: Class - - Selector: alternateSelectedControlTextColor - SwiftName: alternateSelectedControlTextColor() - MethodKind: Class - Selector: 'blendedColorWithFraction:ofColor:' SwiftName: blended(withFraction:of:) MethodKind: Instance @@ -836,16 +907,90 @@ Classes: - Selector: 'shouldBeTreatedAsInkEvent:' SwiftName: shouldBeTreatedAsInkEvent(_:) MethodKind: Instance + - Selector: 'performKeyEquivalent:' + SwiftName: performKeyEquivalent(with:) + MethodKind: Instance + - Selector: 'mouseDown:' + SwiftName: mouseDown(with:) + MethodKind: Instance + - Selector: 'rightMouseDown:' + SwiftName: rightMouseDown(with:) + MethodKind: Instance + - Selector: 'otherMouseDown:' + SwiftName: otherMouseDown(with:) + MethodKind: Instance + - Selector: 'mouseUp:' + SwiftName: mouseUp(with:) + MethodKind: Instance + - Selector: 'rightMouseUp:' + SwiftName: rightMouseUp(with:) + MethodKind: Instance + - Selector: 'otherMouseUp:' + SwiftName: otherMouseUp(with:) + MethodKind: Instance + - Selector: 'mouseMoved:' + SwiftName: mouseMoved(with:) + MethodKind: Instance + - Selector: 'mouseDragged:' + SwiftName: mouseDragged(with:) + MethodKind: Instance + - Selector: 'scrollWheel:' + SwiftName: scrollWheel(with:) + MethodKind: Instance + - Selector: 'rightMouseDragged:' + SwiftName: rightMouseDragged(with:) + MethodKind: Instance + - Selector: 'otherMouseDragged:' + SwiftName: otherMouseDragged(with:) + MethodKind: Instance + - Selector: 'mouseEntered:' + SwiftName: mouseEntered(with:) + MethodKind: Instance + - Selector: 'mouseExited:' + SwiftName: mouseExited(with:) + MethodKind: Instance + - Selector: 'keyDown:' + SwiftName: keyDown(with:) + MethodKind: Instance + - Selector: 'keyUp:' + SwiftName: keyUp(with:) + MethodKind: Instance + - Selector: 'flagsChanged:' + SwiftName: flagsChanged(with:) + MethodKind: Instance + - Selector: 'tabletPoint:' + SwiftName: tabletPoint(with:) + MethodKind: Instance + - Selector: 'tabletProximity:' + SwiftName: tabletProximity(with:) + MethodKind: Instance + - Selector: 'cursorUpdate:' + SwiftName: cursorUpdate(with:) + MethodKind: Instance - Name: NSScroller Methods: - Selector: 'drawArrow:highlight:' SwiftName: drawArrow(_:highlight:) MethodKind: Instance + - Selector: 'trackKnob:' + SwiftName: trackKnob(with:) + MethodKind: Instance + - Selector: 'trackScrollButtons:' + SwiftName: trackScrollButtons(with:) + MethodKind: Instance + - Selector: 'scrollWheel:' + SwiftName: scrollWheel(with:) + MethodKind: Instance - Name: NSSharingServicePicker Methods: - Selector: 'showRelativeToRect:ofView:preferredEdge:' SwiftName: show(relativeTo:of:preferredEdge:) MethodKind: Instance +- Name: NSSlider + Methods: + - Selector: 'acceptsFirstMouse:' + SwiftName: acceptsFirstMouse(for:) + MethodKind: Instance - Name: NSSliderCell Methods: - Selector: 'knobRectFlipped:' @@ -1023,6 +1168,18 @@ Classes: - Selector: 'locationOfPrintRect:' SwiftName: locationOfPrintRect(_:) MethodKind: Instance + - Selector: 'autoscroll:' + SwiftName: autoscroll(with:) + MethodKind: Instance + - Selector: 'performKeyEquivalent:' + SwiftName: performKeyEquivalent(with:) + MethodKind: Instance + - Selector: 'acceptsFirstMouse:' + SwiftName: acceptsFirstMouse(for:) + MethodKind: Instance + - Selector: 'rulerView:handleMouseDown:' + SwiftName: rulerView(_:handleMouseDownWith:) + MethodKind: Instance Properties: - Name: nextKeyView SwiftName: nextKeyView @@ -1097,6 +1254,14 @@ Protocols: - Selector: 'tabViewDidChangeNumberOfTabViewItems:' SwiftName: tabViewDidChangeNumberOfTabViewItems(_:) MethodKind: Instance +- Name: NSTextAttachmentCell + Methods: + - Selector: 'trackMouse:inRect:ofView:untilMouseUp:' + SwiftName: trackMouse(with:in:of:untilMouseUp:) + MethodKind: Instance + - Selector: 'trackMouse:inRect:ofView:atCharacterIndex:untilMouseUp:' + SwiftName: trackMouse(with:in:of:atCharacterIndex:untilMouseUp:) + MethodKind: Instance - Name: NSUserInterfaceValidations Methods: - Selector: 'validateUserInterfaceItem:' diff --git a/apinotes/CMakeLists.txt b/apinotes/CMakeLists.txt index db6013544cb20..cc75dcbb9c7cd 100644 --- a/apinotes/CMakeLists.txt +++ b/apinotes/CMakeLists.txt @@ -51,6 +51,7 @@ set(SWIFT_API_NOTES_INPUTS WebKit XCTest XPC + os ) if(NOT DEFINED SWIFT_API_NOTES_PATH) diff --git a/apinotes/CoreGraphics.apinotes b/apinotes/CoreGraphics.apinotes index c34e8a3a6edaa..80222c835180c 100644 --- a/apinotes/CoreGraphics.apinotes +++ b/apinotes/CoreGraphics.apinotes @@ -79,14 +79,18 @@ Functions: SwiftName: CGAffineTransform.concatenating(self:_:) - Name: CGAffineTransformInvert SwiftName: CGAffineTransform.inverted(self:) -- Name: CGAffineTransformEqualToTransform - SwiftName: CGAffineTransform.equalTo(self:_:) - Name: CGPointApplyAffineTransform SwiftName: CGPoint.applying(self:_:) - Name: CGSizeApplyAffineTransform SwiftName: CGSize.applying(self:_:) - Name: CGRectApplyAffineTransform SwiftName: CGRect.applying(self:_:) +# These are hidden so we can improve them further in the SDK overlay +- Name: CGAffineTransformEqualToTransform + # replaced by Equatable / == + SwiftName: CGAffineTransform.__equalTo(self:_:) + SwiftPrivate: true + # CGBitmapContext - Name: CGBitmapContextCreateWithData SwiftName: CGContext.init(data:width:height:bitsPerComponent:bytesPerRow:space:bitmapInfo:releaseCallback:releaseInfo:) @@ -110,7 +114,9 @@ Functions: SwiftName: getter:CGContext.alphaInfo(self:) - Name: CGBitmapContextCreateImage SwiftName: CGContext.makeImage(self:) + # CGColor +# - Name: CGColorCreate SwiftName: CGColor.init(colorSpace:components:) - Name: CGColorCreateGenericGray @@ -119,19 +125,31 @@ Functions: SwiftName: CGColor.init(red:green:blue:alpha:) - Name: CGColorCreateCMYK SwiftName: CGColor.init(cyan:magenta:yellow:black:alpha:) -- Name: CGColorGetConstantColor - SwiftName: CGColor.constantColor(for:) - Name: CGColorCreateWithPattern SwiftName: CGColor.init(patternSpace:pattern:components:) - Name: CGColorCreateCopy - SwiftName: CGColor.init(_:) -# - Name: CGColorCreateCopyWithAlpha -# SwiftName: CGColor.init(_:alpha:) + SwiftName: CGColor.copy(self:) +- Name: CGColorCreateCopyWithAlpha + SwiftName: CGColor.copy(self:alpha:) - Name: CGColorCreateCopyByMatchingToColorSpace SwiftName: CGColor.converted(to:intent:self:options:) +# Replaced by actual constant colors in the overlay +- Name: CGColorGetConstantColor + SwiftName: CGColor.__constantColor(for:) + SwiftPrivate: true +# Replaced by == operator in the overlay - Name: CGColorEqualToColor - SwiftName: CGColor.equalTo(self:_:) + SwiftName: CGColor.__equalTo(self:_:) + SwiftPrivate: true +# Replaced in the overlay: var components: [CGFloat]? +- Name: CGColorGetComponents + SwiftName: getter:CGColor.__unsafeComponents(self:) + SwiftPrivate: true + + # CGColorSpace +# +# These are cases where we want better names than ImportAsMember inference gets - Name: CGColorSpaceCreateWithICCProfile SwiftName: CGColorSpace.init(iccProfileData:) - Name: CGColorSpaceCreateWithPlatformColorSpace @@ -142,7 +160,27 @@ Functions: SwiftName: getter:CGColorSpace.name(self:) - Name: CGColorSpaceCopyICCProfile SwiftName: getter:CGColorSpace.iccData(self:) +- Name: CGColorSpaceIsWideGamutRGB + SwiftName: getter:CGColorSpace.isWideGamutRGB(self:) +- Name: CGColorSpaceSupportsOutput + SwiftName: getter:CGColorSpace.supportsOutput(self:) +# These are hidden so we can improve them further in the SDK overlay +- Name: CGColorSpaceGetColorTableCount + # merged count and pointer to single array property + SwiftName: getter:CGColorSpace.__colorTableCount(self:) + SwiftPrivate: true +- Name: CGColorSpaceGetColorTable + # merged count and pointer to single array property + SwiftName: CGColorSpace.__unsafeGetColorTable(self:_:) + SwiftPrivate: true + # CGContext +# +# These are cases where we want better names than ImportAsMember inference gets +- Name: CGConttextSaveGState + SwiftName: CGContext.saveGraphicsState(self:) +- Name: CGConttextRestoreGState + SwiftName: CGContext.restoreGraphicsState(self:) - Name: CGContextConcatCTM SwiftName: CGContext.concatenate(self:_:) - Name: CGContextScaleCTM @@ -155,30 +193,12 @@ Functions: SwiftName: CGContext.setLineWidth(self:_:) - Name: CGContextSetMiterLimit SwiftName: CGContext.setMiterLimit(self:_:) -# - Name: CGContextSetLineDash -# SwiftName: CGContext.setLineDash(self:phase:lengths:count:) - Name: CGContextSetFlatness SwiftName: CGContext.setFlatness(self:_:) - Name: CGContextSetAlpha SwiftName: CGContext.setAlpha(self:_:) -- Name: CGContextMoveToPoint - SwiftName: CGContext.moveTo(self:x:y:) -- Name: CGContextAddLineToPoint - SwiftName: CGContext.addLineTo(self:x:y:) -- Name: CGContextAddCurveToPoint - SwiftName: CGContext.addCurveTo(self:cp1x:cp1y:cp2x:cp2y:endingAtX:y:) -- Name: CGContextAddQuadCurveToPoint - SwiftName: CGContext.addQuadCurveTo(self:cpx:cpy:endingAtX:y:) -- Name: CGContextAddRects - SwiftName: CGContext.addRects(self:_:count:) -- Name: CGContextAddLines - SwiftName: CGContext.addLines(self:between:count:) - Name: CGContextAddEllipseInRect - SwiftName: CGContext.addEllipse(self:inRect:) -- Name: CGContextAddArc - SwiftName: CGContext.addArc(self:centerX:y:radius:startAngle:endAngle:clockwise:) -- Name: CGContextAddArcToPoint - SwiftName: CGContext.addArc(self:x1:y1:x2:y2:radius:) + SwiftName: CGContext.addEllipse(self:in:) - Name: CGContextIsPathEmpty SwiftName: getter:CGContext.isPathEmpty(self:) - Name: CGContextGetPathCurrentPoint @@ -186,15 +206,13 @@ Functions: - Name: CGContextGetPathBoundingBox SwiftName: getter:CGContext.boundingBoxOfPath(self:) - Name: CGContextCopyPath - SwiftName: CGContext.path(self:) + SwiftName: getter:CGContext.path(self:) - Name: CGContextPathContainsPoint SwiftName: CGContext.pathContains(self:_:mode:) - Name: CGContextDrawPath SwiftName: CGContext.drawPath(self:using:) - Name: CGContextFillRect SwiftName: CGContext.fill(self:_:) -- Name: CGContextFillRects - SwiftName: CGContext.fill(self:_:count:) - Name: CGContextStrokeRect SwiftName: CGContext.stroke(self:_:) - Name: CGContextStrokeRectWithWidth @@ -205,14 +223,10 @@ Functions: SwiftName: CGContext.fillEllipse(self:in:) - Name: CGContextStrokeEllipseInRect SwiftName: CGContext.strokeEllipse(self:in:) -- Name: CGContextStrokeLineSegments - SwiftName: CGContext.strokeLineSegments(self:between:count:) - Name: CGContextGetClipBoundingBox SwiftName: getter:CGContext.boundingBoxOfClipPath(self:) - Name: CGContextClipToRect SwiftName: CGContext.clip(self:to:) -- Name: CGContextClipToRects - SwiftName: CGContext.clip(self:to:count:) - Name: CGContextClipToMask SwiftName: CGContext.clip(self:to:mask:) - Name: CGContextSetFillColor @@ -241,22 +255,14 @@ Functions: SwiftName: CGContext.setFillColor(self:cyan:magenta:yellow:black:alpha:) - Name: CGContextSetCMYKStrokeColor SwiftName: CGContext.setStrokeColor(self:cyan:magenta:yellow:black:alpha:) -- Name: CGContextDrawImage - SwiftName: CGContext.draw(self:in:image:) -- Name: CGContextDrawTiledImage - SwiftName: CGContext.draw(self:in:byTiling:) - Name: CGContextSetShadowWithColor SwiftName: CGContext.setShadow(self:offset:blur:color:) # - Name: CGContextSetShadow # SwiftName: CGContext.setShadow(self:offset:blur:) - Name: CGContextSetCharacterSpacing SwiftName: CGContext.setCharacterSpacing(self:_:) -- Name: CGContextGetTextPosition - SwiftName: getter:CGContext.textPosition(self:) - Name: CGContextSetFontSize SwiftName: CGContext.setFontSize(self:_:) -- Name: CGContextShowGlyphsAtPositions - SwiftName: CGContext.showGlyphs(self:_:atPositions:count:) # - Name: CGContextBeginPage # SwiftName: CGContext.beginPage(self:mediaBox:) - Name: CGContextSetShouldAntialias @@ -291,11 +297,99 @@ Functions: SwiftName: CGContext.convertToDeviceSpace(self:_:) - Name: CGContextConvertRectToUserSpace SwiftName: CGContext.convertToUserSpace(self:_:) +# These are hidden so we can improve them further in the SDK overlay +- Name: CGContextSetLineDash + # replaced by setLineDash(phase:lengths:) -- array instead of pointer/count + SwiftName: CGContext.__setLineDash(self:phase:lengths:count:) + SwiftPrivate: true +- Name: CGContextMoveToPoint + # replaced by move(to: CGPoint) + SwiftName: CGContext.__moveTo(self:x:y:) + SwiftPrivate: true +- Name: CGContextAddLineToPoint + # replaced by addLine(to: CGPoint) + SwiftName: CGContext.__addLineTo(self:x:y:) + SwiftPrivate: true +- Name: CGContextAddCurveToPoint + # replaced by addCurve(to:control1:control2:) + SwiftName: CGContext.__addCurveTo(self:cp1x:cp1y:cp2x:cp2y:endingAtX:y:) + SwiftPrivate: true +- Name: CGContextAddQuadCurveToPoint + # replaced by addQuadCurve(to:control:) + SwiftName: CGContext.__addQuadCurveTo(self:cpx:cpy:endingAtX:y:) + SwiftPrivate: true +- Name: CGContextAddRects + # replaced by addRects(_:) -- array instead of pointer/count + SwiftName: CGContext.__addRects(self:_:count:) + SwiftPrivate: true +- Name: CGContextAddLines + # replaced by addLines(between:) -- array instead of pointer/count + SwiftName: CGContext.__addLines(self:between:count:) + SwiftPrivate: true +- Name: CGContextAddArc + # replaced by addArc(center:radius:startAngle:endAngle:clockwise:) -- CW is Bool, not Int32 + SwiftName: CGContext.__addArc(self:centerX:y:radius:startAngle:endAngle:clockwise:) + SwiftPrivate: true +- Name: CGContextAddArcToPoint + # replaced by addArc(tangent1End:tangent2End:radius:) + SwiftName: CGContext.__addArc(self:x1:y1:x2:y2:radius:) + SwiftPrivate: true +- Name: CGContextFillRects + # replaced by fill(_ rects: [CGRect]) -- array instead of pointer/count + SwiftName: CGContext.__fill(self:_:count:) + SwiftPrivate: true +- Name: CGContextStrokeLineSegments + # replaced by strokeLineSegments(between points: [CGPoint]) -- array instead of pointer/count + SwiftName: CGContext.__strokeLineSegments(self:between:count:) + SwiftPrivate: true +- Name: CGContextClipToRects + # replaced by clip(to rects: [CGRect]) -- array instead of pointer/count + SwiftName: CGContext.__clip(self:to:count:) + SwiftPrivate: true +- Name: CGContextDrawImage + # replaced by draw(_ image: CGImage, in rect: CGRect, byTiling: Bool = false) + SwiftName: CGContext.__draw(self:in:image:) + SwiftPrivate: true +- Name: CGContextDrawTiledImage + # replaced by draw(_ image: CGImage, in rect: CGRect, byTiling: Bool = false) + SwiftName: CGContext.__draw(self:in:byTiling:) + SwiftPrivate: true +- Name: CGContextGetTextPosition + # replaced by readwrite property + SwiftName: getter:CGContext.__textPosition(self:) + SwiftPrivate: true +- Name: CGContextSetTextPosition + # replaced by readwrite property + SwiftName: CGContext.__setTextPosition(self:x:y:) + SwiftPrivate: true +- Name: CGContextShowGlyphsAtPositions + # replaced by showGlyphs(_:at:) -- array instead of pointer/count + SwiftName: CGContext.__showGlyphs(self:_:atPositions:count:) + SwiftPrivate: true +- Name: CGContextFillPath + # replaced by combining winding and evenOdd rules to one func with an enum + SwiftName: CGContext.__fillPath(self:) + SwiftPrivate: true +- Name: CGContextEOFillPath + # replaced by combining winding and evenOdd rules to one func with an enum + # has nothing to do with Enterprise Objects + SwiftName: CGContext.__eoFillPath(self:) + SwiftPrivate: true +- Name: CGContextClip + # replaced by combining winding and evenOdd rules to one func with an enum + SwiftName: CGContext.__clip(self:) + SwiftPrivate: true +- Name: CGContextEOClip + # replaced by combining winding and evenOdd rules to one func with an enum + SwiftName: CGContext.__eoClip(self:) + SwiftPrivate: true + # CGDataConsumer # - Name: CGDataConsumerCreateWithURL # SwiftName: CGDataConsumer.init(url:) # - Name: CGDataConsumerCreateWithCFData # SwiftName: CGDataConsumer.init(data:) + # CGDataProvider # - Name: CGDataProviderCreateWithData # SwiftName: CGDataProvider.init(dataInfo:data:size:releaseData:) @@ -303,15 +397,20 @@ Functions: # SwiftName: CGDataProvider.init(data:) # - Name: CGDataProviderCreateWithURL # SwiftName: CGDataProvider.init(url:) -# - Name: CGDataProviderCreateWithFilename -# SwiftName: CGDataProvider.init(filename:) - Name: CGDataProviderCopyData SwiftName: getter:CGDataProvider.data(self:) + # CGDirectDisplay - Name: CGDisplayModeCopyPixelEncoding SwiftName: getter:CGDisplayMode.pixelEncoding(self:) - Name: CGDisplayCreateImageForRect SwiftName: CGDisplayCreateImage(_:rect:) +# These are hidden so we can improve them further in the SDK overlay +- Name: CGGetLastMouseDelta + # replaced by a version that returns CGVector instead of using out-pointers + SwiftName: __CGGetLastMouseDelta + SwiftPrivate: true + # CGEvent - Name: CGEventCreateFromData SwiftName: CGEvent.init(withDataAllocator:data:) @@ -323,6 +422,7 @@ Functions: SwiftName: CGEvent.postToPid(_:self:) - Name: CGEventCreateSourceFromEvent SwiftName: CGEventSource.init(event:) + # CGFont - Name: CGFontCreateWithDataProvider SwiftName: CGFont.init(_:) @@ -342,49 +442,75 @@ Functions: SwiftName: getter:CGFont.tableTags(self:) - Name: CGFontCopyTableForTag SwiftName: CGFont.table(self:for:) +- Name: CGFontCreateCopyWithVariations + SwiftName: CGFont.copy(self:withVariations:) + # CGGeometry -- Name: CGPointEqualToPoint - SwiftName: CGPoint.equalTo(self:_:) - Name: CGPointCreateDictionaryRepresentation SwiftName: getter:CGPoint.dictionaryRepresentation(self:) +- Name: CGSizeCreateDictionaryRepresentation + SwiftName: getter:CGSize.dictionaryRepresentation(self:) - Name: CGRectCreateDictionaryRepresentation SwiftName: getter:CGRect.dictionaryRepresentation(self:) -- Name: CGPointMakeWithDictionaryRepresentation - SwiftName: CGPoint.makeWithDictionaryRepresentation(_:self:) -- Name: CGSizeMakeWithDictionaryRepresentation - SwiftName: CGSize.makeWithDictionaryRepresentation(_:self:) -- Name: CGRectMakeWithDictionaryRepresentation - SwiftName: CGRect.makeWithDictionaryRepresentation(_:self:) +- Name: CGPointEqualToPoint + SwiftName: CGPoint.equalTo(self:_:) - Name: CGSizeEqualToSize SwiftName: CGSize.equalTo(self:_:) - Name: CGRectEqualToRect SwiftName: CGRect.equalTo(self:_:) +# These are hidden so we can improve them further in the SDK overlay - Name: CGRectDivide - SwiftName: CGRect.divided(self:slice:remainder:atDistance:from:) + # hide the pointer version in favor of the tuple-return version + SwiftName: CGRect.__divided(self:slice:remainder:atDistance:from:) + SwiftPrivate: true +- Name: CGPointMakeWithDictionaryRepresentation + # hide in favor of an init (can't map to initializer because out-pointer) + SwiftName: CGPoint.__setFromDictionaryRepresentation(_:_:) + SwiftPrivate: true +- Name: CGSizeMakeWithDictionaryRepresentation + # hide in favor of an init (can't map to initializer because out-pointer) + SwiftName: CGSize.__setFromDictionaryRepresentation(_:_:) + SwiftPrivate: true +- Name: CGRectMakeWithDictionaryRepresentation + # hide in favor of an init (can't map to initializer because out-pointer) + SwiftName: CGRect.__setFromDictionaryRepresentation(_:_:) + SwiftPrivate: true + # CGGradient -# - Name: CGGradientCreateWithColorComponents -# SwiftName: CGGradient.init(colorComponentsSpace:components:locations:count:) -# - Name: CGGradientCreateWithColorSpace -# SwiftName: CGGradient.init(colorSpace:colors:locations:) +- Name: CGGradientCreateWithColorComponents + SwiftName: CGGradient.init(colorSpace:colorComponents:locations:count:) +- Name: CGGradientCreateWithColorSpace + SwiftName: CGGradient.init(colorSpace:colors:locations:) # CGImage +- Name: CGImageCreateCopy + SwiftName: CGImage.copy(self:) - Name: CGImageCreateCopyWithColorSpace SwiftName: CGImage.copy(self:colorSpace:) - Name: CGImageCreateWithImageInRect SwiftName: CGImage.cropping(self:to:) - Name: CGImageCreateWithMask SwiftName: CGImage.masking(self:_:) -- Name: CGImageCreateWithMaskingColors - SwiftName: CGImage.copy(self:maskingColorComponents:) - Name: CGImageIsMask SwiftName: getter:CGImage.isMask(self:) +# These are hidden so we can improve them further in the SDK overlay +- Name: CGImageCreateWithMaskingColors + # replaced by a version that takes an array instead of UnsafePointer + SwiftName: CGImage.__copy(self:maskingColorComponents:) + SwiftPrivate: true + # CGLayer - Name: CGLayerCreateWithContext SwiftName: CGLayer.init(_:size:auxiliaryInfo:) +# These are hidden so we can improve them further in the SDK overlay - Name: CGContextDrawLayerInRect - SwiftName: CGContext.draw(self:in:layer:) + # API notes can't rearrange args, want layer first to match draw(image:) etc + SwiftName: CGContext.__draw(self:in:layer:) + SwiftPrivate: true - Name: CGContextDrawLayerAtPoint - SwiftName: CGContext.draw(self:at:layer:) + # API notes can't rearrange args, want layer first to match draw(image:) etc + SwiftName: CGContext.__draw(self:at:layer:) + SwiftPrivate: true # CGPDFContext - Name: CGPDFContextCreate @@ -432,6 +558,7 @@ Functions: # CGPSConverter - Name: CGPSConverterIsConverting SwiftName: getter:CGPSConverter.isConverting(self:) + # CGPath - Name: CGPathCreateCopy SwiftName: CGPath.copy(self:) @@ -441,36 +568,78 @@ Functions: SwiftName: CGPath.mutableCopy(self:) - Name: CGPathCreateMutableCopyByTransformingPath SwiftName: CGPath.mutableCopy(self:using:) -- Name: CGPathEqualToPath - SwiftName: CGPath.equalTo(self:_:) - Name: CGPathGetPathBoundingBox SwiftName: getter:CGPath.boundingBoxOfPath(self:) +- Name: CGPathIsEmpty + SwiftName: getter:CGPath.isEmpty(self:) +# These are hidden so we can improve them further in the SDK overlay +- Name: CGPathCreateCopyByDashingPath + # replaced by copy(...) method, move transform to end, pointer/count => array + SwiftName: CGPath.init(__byDashing:transform:phase:lengths:count:) + SwiftPrivate: true +- Name: CGPathCreateCopyByStrokingPath + # replaced by copy(...) method, move transform to end + SwiftName: CGPath.init(__byStroking:transform:lineWidth:lineCap:lineJoin:miterLimit:) + SwiftPrivate: true - Name: CGPathContainsPoint - SwiftName: CGPath.containsPoint(self:_:point:eoFill:) + # replaced to move transform to end + # TODO: replace eoFill with a FillRule enum for clarity + SwiftName: CGPath.__containsPoint(self:transform:point:eoFill:) + SwiftPrivate: true +- Name: CGPathEqualToPath + # replaced in favor of == / Equatable + SwiftName: CGPath.__equalTo(self:_:) + SwiftPrivate: true +- Name: CGPathAddRoundedRect + SwiftName: CGMutablePath.__addRoundedRect(self:transform:rect:cornerWidth:cornerHeight:) - Name: CGPathMoveToPoint - SwiftName: CGMutablePath.moveTo(self:_:x:y:) + # replaced to use CGPoint, move transform to end + SwiftName: CGMutablePath.__moveTo(self:transform:x:y:) + SwiftPrivate: true - Name: CGPathAddLineToPoint - SwiftName: CGMutablePath.addLineTo(self:_:x:y:) + # replaced to use CGPoint, move transform to end + SwiftName: CGMutablePath.__addLineTo(self:transform:x:y:) + SwiftPrivate: true - Name: CGPathAddCurveToPoint - SwiftName: CGMutablePath.addCurve(self:_:cp1x:cp1y:cp2x:cp2y:endingAtX:y:) + # replaced to use CGPoint, move transform to end + SwiftName: CGMutablePath.__addCurve(self:transform:cp1x:cp1y:cp2x:cp2y:endingAtX:y:) + SwiftPrivate: true - Name: CGPathAddQuadCurveToPoint - SwiftName: CGMutablePath.addQuadCurve(self:_:cpx:cpy:endingAtX:y:) + # replaced to use CGPoint, move transform to end + SwiftName: CGMutablePath.__addQuadCurve(self:transform:cpx:cpy:endingAtX:y:) + SwiftPrivate: true - Name: CGPathAddRect - SwiftName: CGMutablePath.addRect(self:_:rect:) + # replaced to move transform to end + SwiftName: CGMutablePath.__addRect(self:transform:rect:) + SwiftPrivate: true - Name: CGPathAddRects - SwiftName: CGMutablePath.addRects(self:_:rects:count:) + # replaced to move transform to end, use array not pointer/count + SwiftName: CGMutablePath.__addRects(self:transform:rects:count:) + SwiftPrivate: true - Name: CGPathAddLines - SwiftName: CGMutablePath.addLines(self:_:between:count:) + # replaced to use CGPoint, move transform to end, use array not pointer/count + SwiftName: CGMutablePath.__addLines(self:transform:between:count:) + SwiftPrivate: true - Name: CGPathAddEllipseInRect - SwiftName: CGMutablePath.addEllipseIn(self:_:rect:) + # replaced to use CGPoint, move transform to end + SwiftName: CGMutablePath.__addEllipse(self:transform:rect:) + SwiftPrivate: true +- Name: CGPathAddRelativeArc + # replaced to use CGPoint, move transform to end + SwiftName: CGMutablePath.__addRelativeArc(self:transform:x:y:radius:startAngle:delta:) + SwiftPrivate: true - Name: CGPathAddArc - SwiftName: CGMutablePath.addArc(self:_:x:y:radius:startAngle:endAngle:clockwise:) + # replaced to use CGPoint, move transform to end + SwiftName: CGMutablePath.__addArc(self:transform:x:y:radius:startAngle:endAngle:clockwise:) + SwiftPrivate: true - Name: CGPathAddArcToPoint - SwiftName: CGMutablePath.addArc(self:_:x1:y1:x2:y2:radius:) + # replaced to use CGPoint, move transform to end + SwiftName: CGMutablePath.__addArc(self:transform:x1:y1:x2:y2:radius:) + SwiftPrivate: true - Name: CGPathAddPath - SwiftName: CGMutablePath.addPath(self:_:path:) -- Name: CGPathIsEmpty - SwiftName: getter:CGPath.isEmpty(self:) + # replaced to move transform to end + SwiftName: CGMutablePath.__addPath(self:transform:path:) + SwiftPrivate: true # # Global variables @@ -495,6 +664,16 @@ Globals: Availability: nonswift - Name: kCGColorSpaceSRGB SwiftName: CGColorSpace.sRGB +# These are actual constant colors, not color names, in the overlay +- Name: kCGColorWhite + SwiftName: CGColor.__whiteColorName + SwiftPrivate: true +- Name: kCGColorBlack + SwiftName: CGColor.__blackColorName + SwiftPrivate: true +- Name: kCGColorClear + SwiftName: CGColor.__clearColorName + SwiftPrivate: true # # Enums diff --git a/apinotes/GameplayKit.apinotes b/apinotes/GameplayKit.apinotes index 24ec198f8fcf4..b5b8025bc579c 100644 --- a/apinotes/GameplayKit.apinotes +++ b/apinotes/GameplayKit.apinotes @@ -253,8 +253,8 @@ Classes: SwiftName: enter(_:) MethodKind: Instance - Selector: 'stateForClass:' - SwiftName: state(for:) MethodKind: Instance + SwiftPrivate: true - Name: SKTileMapNode Methods: - Selector: 'tileMapNodesWithTileSet:columns:rows:tileSize:fromNoiseMap:tileTypeNoiseMapThresholds:' diff --git a/apinotes/UIKit.apinotes b/apinotes/UIKit.apinotes index 5b1f42abe026a..6ff86f6105c8f 100644 --- a/apinotes/UIKit.apinotes +++ b/apinotes/UIKit.apinotes @@ -12,10 +12,9 @@ Classes: MethodKind: Class FactoryAsInit: C - Name: UIPrintInteractionController - Methods: - - Selector: 'sharedPrintController' - SwiftName: shared() - MethodKind: Class + Properties: + - Name: 'sharedPrintController' + SwiftName: shared - Name: NSLayoutAnchor Methods: - Selector: 'constraintEqualToAnchor:' @@ -196,10 +195,10 @@ Classes: SwiftName: size(forNumberOfPages:) MethodKind: Instance - Name: UIPasteboard + Properties: + - Name: pasteboardTypes + SwiftName: types Methods: - - Selector: pasteboardTypes - SwiftName: types() - MethodKind: Instance - Selector: 'containsPasteboardTypes:' SwiftName: contains(pasteboardTypes:) MethodKind: Instance @@ -242,6 +241,16 @@ Classes: - Selector: 'touchesShouldCancelInContentView:' SwiftName: touchesShouldCancel(in:) MethodKind: Instance +- Name: UIStoryboardSegue + Properties: + - Name: sourceViewController + SwiftName: source + - Name: destinationViewController + SwiftName: destination +- Name: UIStoryboardUnwindSegueSource + Properties: + - Name: sourceViewController + SwiftName: source - Name: UIUserNotificationSettings Methods: - Selector: 'settingsForTypes:categories:' diff --git a/apinotes/os.apinotes b/apinotes/os.apinotes new file mode 100644 index 0000000000000..9957c555fa005 --- /dev/null +++ b/apinotes/os.apinotes @@ -0,0 +1,42 @@ +Name: os +Typedefs: +- Name: os_log_type_t + SwiftName: OSLogType +- Name: os_trace_payload_t + Availability: nonswift +- Name: os_log_t + Availability: nonswift +Classes: +- Name: OS_os_log + SwiftName: OSLog +Enumerators: +- Name: OS_LOG_TYPE_DEFAULT + SwiftPrivate: true +- Name: OS_LOG_TYPE_INFO + SwiftPrivate: true +- Name: OS_LOG_TYPE_DEBUG + SwiftPrivate: true +- Name: OS_LOG_TYPE_ERROR + SwiftPrivate: true +- Name: OS_LOG_TYPE_FAULT + SwiftPrivate: true +Functions: +- Name: _os_log_impl + Availability: nonswift + AvailabilityMsg: 'Use os_log' +- Name: _os_log_sensitive_deprecated + Availability: nonswift +- Name: _os_trace_with_buffer + Availability: nonswift +- Name: os_log_is_enabled + Availability: nonswift +- Name: os_log_type_enabled + SwiftName: 'OSLog.isEnabled(self:type:)' +- Name: _os_log_create + Availability: nonswift +- Name: os_log_create + SwiftName: 'OSLog.init(__subsystem:category:)' + SwiftPrivate: true + NullabilityOfRet: N +- Name: os_log_is_debug_enabled + Availability: nonswift diff --git a/include/swift/AST/ASTContext.h b/include/swift/AST/ASTContext.h index a69c915f3e998..0756059c1e7a0 100644 --- a/include/swift/AST/ASTContext.h +++ b/include/swift/AST/ASTContext.h @@ -364,7 +364,7 @@ class ASTContext { PrecedenceGroupDecl *right) const; /// Retrieve the declaration of Swift.Error. - NominalTypeDecl *getErrorDecl() const; + ProtocolDecl *getErrorDecl() const; CanType getExceptionType() const; /// Retrieve the declaration of Swift.Bool. diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index d2462da132c6c..da88ea71cd8cf 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -283,6 +283,10 @@ ERROR(cannot_convert_to_return_type_nil,none, ERROR(cannot_convert_thrown_type,none, "thrown expression type %0 does not conform to 'Error'", (Type)) +ERROR(cannot_throw_error_code,none, + "thrown error code type %0 does not conform to 'Error'; construct an %1 " + "instance", (Type, Type)) + ERROR(cannot_throw_nil,none, "cannot infer concrete Error for thrown 'nil' value", ()) @@ -2306,6 +2310,15 @@ ERROR(closure_noescape_use,none, ERROR(decl_closure_noescape_use,none, "declaration closing over non-escaping parameter %0 may allow it to escape", (Identifier)) +ERROR(passing_noescape_to_escaping,none, + "passing non-escaping parameter %0 to function expecting an @escaping closure", + (Identifier)) +ERROR(assigning_noescape_to_escaping,none, + "assigning non-escaping parameter %0 to an @escaping closure", + (Identifier)) +ERROR(general_noescape_to_escaping,none, + "using non-escaping parameter %0 in a context expecting an @escaping closure", + (Identifier)) ERROR(capture_across_type_decl,none, "%0 declaration cannot close over value %1 defined in outer scope", diff --git a/include/swift/AST/KnownDecls.def b/include/swift/AST/KnownDecls.def index f4d371d0427ff..d6e643be5e0ce 100644 --- a/include/swift/AST/KnownDecls.def +++ b/include/swift/AST/KnownDecls.def @@ -71,4 +71,6 @@ FUNC_DECL(BridgeAnythingToObjectiveC, FUNC_DECL(DidEnterMain, "_stdlib_didEnterMain") FUNC_DECL(DiagnoseUnexpectedNilOptional, "_diagnoseUnexpectedNilOptional") +FUNC_DECL(GetErrorEmbeddedNSError, "_stdlib_getErrorEmbeddedNSError") + #undef FUNC_DECL diff --git a/include/swift/SIL/SILCloner.h b/include/swift/SIL/SILCloner.h index b626080ba76c0..66ed0f72c42a7 100644 --- a/include/swift/SIL/SILCloner.h +++ b/include/swift/SIL/SILCloner.h @@ -66,6 +66,14 @@ class SILCloner : protected SILVisitor { SILBuilder &getBuilder() { return Builder; } protected: + void beforeVisit(ValueBase *V) { + if (auto I = dyn_cast(V)) { + // Update the set of available opened archetypes with the opened + // archetypes used by the current instruction. + doPreProcess(I); + } + } + #define VALUE(CLASS, PARENT) \ void visit##CLASS(CLASS *I) { \ llvm_unreachable("SILCloner visiting non-instruction?"); \ @@ -380,9 +388,6 @@ SILCloner::visitSILBasicBlock(SILBasicBlock* BB) { SILFunction &F = getBuilder().getFunction(); // Iterate over and visit all instructions other than the terminator to clone. for (auto I = BB->begin(), E = --BB->end(); I != E; ++I) { - // Update the set of available opened archetypes with the opened archetypes - // used by the current instruction. - doPreProcess(&*I); asImpl().visit(&*I); } // Iterate over successors to do the depth-first search. diff --git a/include/swift/SIL/SILVisitor.h b/include/swift/SIL/SILVisitor.h index e9366a2c89b55..d644c9a238dea 100644 --- a/include/swift/SIL/SILVisitor.h +++ b/include/swift/SIL/SILVisitor.h @@ -31,7 +31,15 @@ class SILVisitor { public: ImplClass &asImpl() { return static_cast(*this); } + // Peform any required pre-processing before visiting. + // Sub-classes can override it to provide their custom + // pre-processing steps. + void beforeVisit(ValueBase *V) { + } + ValueRetTy visit(ValueBase *V) { + asImpl().beforeVisit(V); + switch (V->getKind()) { #define VALUE(CLASS, PARENT) \ case ValueKind::CLASS: \ diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 803db403accd0..625f601849c3b 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -612,7 +612,7 @@ CanType ASTContext::getExceptionType() const { } } -NominalTypeDecl *ASTContext::getErrorDecl() const { +ProtocolDecl *ASTContext::getErrorDecl() const { return getProtocol(KnownProtocolKind::Error); } diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index 0fc0cc7e9b328..38eccbe0de392 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -357,11 +357,20 @@ getNormalInvocationArguments(std::vector &invocationArgStrs, // frameworks are broken by it. "-D_ISO646_H_", "-D__ISO646_H", + // Request new APIs from AppKit. + "-DSWIFT_SDK_OVERLAY_APPKIT_EPOCH=2", + // Request new APIs from Foundation. "-DSWIFT_SDK_OVERLAY_FOUNDATION_EPOCH=8", // Request new APIs from SceneKit. - "-DSWIFT_SDK_OVERLAY2_SCENEKIT_EPOCH=2", + "-DSWIFT_SDK_OVERLAY2_SCENEKIT_EPOCH=3", + + // Request new APIs from GameplayKit. + "-DSWIFT_SDK_OVERLAY_GAMEPLAYKIT_EPOCH=1", + + // Request new APIs from SpriteKit. + "-DSWIFT_SDK_OVERLAY_SPRITEKIT_EPOCH=1", // Request new APIs from CoreImage. "-DSWIFT_SDK_OVERLAY_COREIMAGE_EPOCH=2", @@ -374,6 +383,9 @@ getNormalInvocationArguments(std::vector &invocationArgStrs, // Request new APIs from CoreGraphics. "-DSWIFT_SDK_OVERLAY_COREGRAPHICS_EPOCH=0", + + // Request new APIs from UIKit. + "-DSWIFT_SDK_OVERLAY_UIKIT_EPOCH=2", }); // Get the version of this compiler and pass it to diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index 1398d706c8b85..de55096fe546a 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -2499,6 +2499,10 @@ namespace { if (!result) return nullptr; + // HACK: Make sure PrintAsObjC always omits the 'enum' tag for + // option set enums. + Impl.DeclsWithSuperfluousTypedefs.insert(decl); + enumeratorContext = result; break; } diff --git a/lib/Driver/Compilation.cpp b/lib/Driver/Compilation.cpp index bec468217b3bc..13b559beeafa3 100644 --- a/lib/Driver/Compilation.cpp +++ b/lib/Driver/Compilation.cpp @@ -456,6 +456,69 @@ int Compilation::performJobsImpl() { llvm::errs() << Output; } + // In order to handle both old dependencies that have disappeared and new + // dependencies that have arisen, we need to reload the dependency file. + // Do this whether or not the build succeeded. + SmallVector Dependents; + if (getIncrementalBuildEnabled()) { + const CommandOutput &Output = FinishedCmd->getOutput(); + StringRef DependenciesFile = + Output.getAdditionalOutputForType(types::TY_SwiftDeps); + if (!DependenciesFile.empty() && + (ReturnCode == EXIT_SUCCESS || ReturnCode == EXIT_FAILURE)) { + bool wasCascading = DepGraph.isMarked(FinishedCmd); + + switch (DepGraph.loadFromPath(FinishedCmd, DependenciesFile)) { + case DependencyGraphImpl::LoadResult::HadError: + if (ReturnCode == EXIT_SUCCESS) { + disableIncrementalBuild(); + for (const Job *Cmd : DeferredCommands) + scheduleCommandIfNecessaryAndPossible(Cmd); + DeferredCommands.clear(); + Dependents.clear(); + } // else, let the next build handle it. + break; + case DependencyGraphImpl::LoadResult::UpToDate: + if (!wasCascading) + break; + SWIFT_FALLTHROUGH; + case DependencyGraphImpl::LoadResult::AffectsDownstream: + DepGraph.markTransitive(Dependents, FinishedCmd); + break; + } + } else { + // If there's a crash, assume the worst. + switch (FinishedCmd->getCondition()) { + case Job::Condition::NewlyAdded: + // The job won't be treated as newly added next time. Conservatively + // mark it as affecting other jobs, because some of them may have + // completed already. + DepGraph.markTransitive(Dependents, FinishedCmd); + break; + case Job::Condition::Always: + // This applies to non-incremental tasks as well, but any incremental + // task that shows up here has already been marked. + break; + case Job::Condition::RunWithoutCascading: + // If this file changed, it might have been a non-cascading change and + // it might not. Unfortunately, the interface hash has been updated or + // compromised, so we don't actually know anymore; we have to + // conservatively assume the changes could affect other files. + DepGraph.markTransitive(Dependents, FinishedCmd); + break; + case Job::Condition::CheckDependencies: + // If the only reason we're running this is because something else + // changed, then we can trust the dependency graph as to whether it's + // a cascading or non-cascading change. That is, if whatever /caused/ + // the error isn't supposed to affect other files, and whatever + // /fixes/ the error isn't supposed to affect other files, then + // there's no need to recompile any other inputs. If either of those + // are false, we /do/ need to recompile other inputs. + break; + } + } + } + if (ReturnCode != EXIT_SUCCESS) { // The task failed, so return true without performing any further // dependency analysis. @@ -481,39 +544,10 @@ int Compilation::performJobsImpl() { // might have been blocked. markFinished(FinishedCmd); - // In order to handle both old dependencies that have disappeared and new - // dependencies that have arisen, we need to reload the dependency file. - if (getIncrementalBuildEnabled()) { - const CommandOutput &Output = FinishedCmd->getOutput(); - StringRef DependenciesFile = - Output.getAdditionalOutputForType(types::TY_SwiftDeps); - if (!DependenciesFile.empty()) { - SmallVector Dependents; - bool wasCascading = DepGraph.isMarked(FinishedCmd); - - switch (DepGraph.loadFromPath(FinishedCmd, DependenciesFile)) { - case DependencyGraphImpl::LoadResult::HadError: - disableIncrementalBuild(); - for (const Job *Cmd : DeferredCommands) - scheduleCommandIfNecessaryAndPossible(Cmd); - DeferredCommands.clear(); - Dependents.clear(); - break; - case DependencyGraphImpl::LoadResult::UpToDate: - if (!wasCascading) - break; - SWIFT_FALLTHROUGH; - case DependencyGraphImpl::LoadResult::AffectsDownstream: - DepGraph.markTransitive(Dependents, FinishedCmd); - break; - } - - for (const Job *Cmd : Dependents) { - DeferredCommands.erase(Cmd); - noteBuilding(Cmd, "because of dependencies discovered later"); - scheduleCommandIfNecessaryAndPossible(Cmd); - } - } + for (const Job *Cmd : Dependents) { + DeferredCommands.erase(Cmd); + noteBuilding(Cmd, "because of dependencies discovered later"); + scheduleCommandIfNecessaryAndPossible(Cmd); } return TaskFinishedResponse::ContinueExecution; diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 6c380b622c861..1019f9ef044ee 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -1604,36 +1604,40 @@ handleCompileJobCondition(Job *J, CompileJobAction::InputInfo inputInfo, return; } - if (!alwaysRebuildDependents) { - // Default all non-newly added files to being rebuilt without cascading. - J->setCondition(Job::Condition::RunWithoutCascading); - } - + bool hasValidModTime = false; llvm::sys::fs::file_status inputStatus; - if (llvm::sys::fs::status(input, inputStatus)) - return; - - J->setInputModTime(inputStatus.getLastModificationTime()); - if (J->getInputModTime() != inputInfo.previousModTime) - return; + if (!llvm::sys::fs::status(input, inputStatus)) { + J->setInputModTime(inputStatus.getLastModificationTime()); + hasValidModTime = true; + } Job::Condition condition; - switch (inputInfo.status) { - case CompileJobAction::InputInfo::UpToDate: - if (!llvm::sys::fs::exists(J->getOutput().getPrimaryOutputFilename())) + if (!hasValidModTime || J->getInputModTime() != inputInfo.previousModTime) { + if (alwaysRebuildDependents || + inputInfo.status == CompileJobAction::InputInfo::NeedsCascadingBuild) { + condition = Job::Condition::Always; + } else { condition = Job::Condition::RunWithoutCascading; - else - condition = Job::Condition::CheckDependencies; - break; - case CompileJobAction::InputInfo::NeedsCascadingBuild: - condition = Job::Condition::Always; - break; - case CompileJobAction::InputInfo::NeedsNonCascadingBuild: - condition = Job::Condition::RunWithoutCascading; - break; - case CompileJobAction::InputInfo::NewlyAdded: - llvm_unreachable("handled above"); + } + } else { + switch (inputInfo.status) { + case CompileJobAction::InputInfo::UpToDate: + if (!llvm::sys::fs::exists(J->getOutput().getPrimaryOutputFilename())) + condition = Job::Condition::RunWithoutCascading; + else + condition = Job::Condition::CheckDependencies; + break; + case CompileJobAction::InputInfo::NeedsCascadingBuild: + condition = Job::Condition::Always; + break; + case CompileJobAction::InputInfo::NeedsNonCascadingBuild: + condition = Job::Condition::RunWithoutCascading; + break; + case CompileJobAction::InputInfo::NewlyAdded: + llvm_unreachable("handled above"); + } } + J->setCondition(condition); } diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp index 189cffaa4036d..9c4a36ecd854c 100644 --- a/lib/FrontendTool/FrontendTool.cpp +++ b/lib/FrontendTool/FrontendTool.cpp @@ -601,6 +601,9 @@ class JSONFixitWriter : public DiagnosticConsumer { Info.ID == diag::convert_let_to_var.ID || Info.ID == diag::parameter_extraneous_double_up.ID || Info.ID == diag::attr_decl_attr_now_on_type.ID || + Info.ID == diag::noescape_parameter.ID || + Info.ID == diag::noescape_autoclosure.ID || + Info.ID == diag::where_inside_brackets.ID || Info.ID == diag::selector_construction_suggest.ID || Info.ID == diag::selector_literal_deprecated_suggest.ID) return true; diff --git a/lib/IRGen/GenStruct.cpp b/lib/IRGen/GenStruct.cpp index b17f2f17b257e..83934b42e7db2 100644 --- a/lib/IRGen/GenStruct.cpp +++ b/lib/IRGen/GenStruct.cpp @@ -579,7 +579,6 @@ class ClangRecordLowering { const clang::ASTContext &ClangContext; const clang::ASTRecordLayout &ClangLayout; const Size TotalStride; - Size TotalSize; const Alignment TotalAlignment; SpareBitVector SpareBits; @@ -595,9 +594,8 @@ class ClangRecordLowering { ClangDecl(clangDecl), ClangContext(clangDecl->getASTContext()), ClangLayout(ClangContext.getASTRecordLayout(clangDecl)), TotalStride(Size(ClangLayout.getSize().getQuantity())), - TotalSize(TotalStride), TotalAlignment(Alignment(ClangLayout.getAlignment().getQuantity())) { - SpareBits.reserve(TotalSize.getValue() * 8); + SpareBits.reserve(TotalStride.getValue() * 8); } void collectRecordFields() { @@ -606,17 +604,12 @@ class ClangRecordLowering { } else { collectStructFields(); } - - // Lots of layout will get screwed up if our structure claims more - // storage than we allocated to it. - assert(NextOffset == TotalSize && NextOffset <= TotalStride); - assert(TotalSize.roundUpToAlignment(TotalAlignment) == TotalStride); } const TypeInfo *createTypeInfo(llvm::StructType *llvmType) { llvmType->setBody(LLVMFields, /*packed*/ true); return ClangRecordTypeInfo::create(FieldInfos, NextExplosionIndex, - llvmType, TotalSize, + llvmType, TotalStride, std::move(SpareBits), TotalAlignment, ClangDecl); } @@ -624,7 +617,7 @@ class ClangRecordLowering { private: /// Collect all the fields of a union. void collectUnionFields() { - addOpaqueField(Size(0), TotalSize); + addOpaqueField(Size(0), TotalStride); } static bool isImportOfClangField(VarDecl *swiftField, @@ -689,8 +682,14 @@ class ClangRecordLowering { assert(sfi == sfe && "more Swift fields than there were Clang fields?"); - // Treat this as the end of the value size. - TotalSize = NextOffset; + // We never take advantage of tail padding, because that would prevent + // us from passing the address of the object off to C, which is a pretty + // likely scenario for imported C types. + assert(NextOffset <= TotalStride); + assert(SpareBits.size() <= TotalStride.getValueInBits()); + if (NextOffset < TotalStride) { + addPaddingField(TotalStride); + } } /// Place the next struct field at its appropriate offset. diff --git a/lib/PrintAsObjC/PrintAsObjC.cpp b/lib/PrintAsObjC/PrintAsObjC.cpp index 952aef0d240b3..7c11609f87abe 100644 --- a/lib/PrintAsObjC/PrintAsObjC.cpp +++ b/lib/PrintAsObjC/PrintAsObjC.cpp @@ -15,6 +15,7 @@ #include "swift/AST/AST.h" #include "swift/AST/ASTVisitor.h" #include "swift/AST/ForeignErrorConvention.h" +#include "swift/AST/NameLookup.h" #include "swift/AST/PrettyStackTrace.h" #include "swift/AST/TypeVisitor.h" #include "swift/AST/Comment.h" @@ -37,16 +38,24 @@ using namespace swift; -static bool isNSObject(ASTContext &ctx, Type type) { +static bool isNSObjectOrAnyHashable(ASTContext &ctx, Type type) { if (auto classDecl = type->getClassOrBoundGenericClass()) { return classDecl->getName() == ctx.getSwiftId(KnownFoundationEntity::NSObject) && classDecl->getModuleContext()->getName() == ctx.Id_ObjectiveC; } + if (auto nomDecl = type->getAnyNominal()) { + return nomDecl->getName() == ctx.getIdentifier("AnyHashable") && + nomDecl->getModuleContext() == ctx.getStdlibModule(); + } return false; } +static bool isAnyObjectOrAny(Type type) { + return type->isAnyObject() || type->isAny(); +} + /// Returns true if \p name matches a keyword in any Clang language mode. static bool isClangKeyword(Identifier name) { static const llvm::StringSet<> keywords = []{ @@ -88,9 +97,13 @@ static StringRef getNameForObjC(const ValueDecl *VD, if (customNamesOnly) return StringRef(); - if (auto clangDecl = dyn_cast_or_null(VD->getClangDecl())) + if (auto clangDecl = dyn_cast_or_null(VD->getClangDecl())) { if (const clang::IdentifierInfo *II = clangDecl->getIdentifier()) return II->getName(); + if (auto *anonDecl = dyn_cast(clangDecl)) + if (auto *anonTypedef = anonDecl->getTypedefNameForAnonDecl()) + return anonTypedef->getIdentifier()->getName(); + } return VD->getName().str(); } @@ -125,6 +138,8 @@ class ObjCPrinter : private DeclVisitor, Accessibility minRequiredAccess; bool protocolMembersOptional = false; + Optional NSCopyingType; + friend ASTVisitor; friend TypeVisitor; @@ -859,6 +874,8 @@ class ObjCPrinter : private DeclVisitor, auto &ctx = swiftNominal->getASTContext(); assert(objcClass); + Type rewrittenArgsBuf[2]; + // Detect when the type arguments correspond to the unspecialized // type, and clear them out. There is some type-specific hackery // here for: @@ -867,13 +884,38 @@ class ObjCPrinter : private DeclVisitor, // NSDictionary --> NSDictionary // NSSet --> NSSet if (!typeArgs.empty() && - (!hasGenericObjCType(objcClass) || - (swiftNominal == ctx.getArrayDecl() && typeArgs[0]->isAnyObject()) || - (swiftNominal == ctx.getDictionaryDecl() && - isNSObject(ctx, typeArgs[0]) && typeArgs[1]->isAnyObject()) || - (swiftNominal == ctx.getSetDecl() && isNSObject(ctx, typeArgs[0])))) { + (!hasGenericObjCType(objcClass) + || (swiftNominal == ctx.getArrayDecl() && + isAnyObjectOrAny(typeArgs[0])) + || (swiftNominal == ctx.getDictionaryDecl() && + isNSObjectOrAnyHashable(ctx, typeArgs[0]) && + isAnyObjectOrAny(typeArgs[1])) + || (swiftNominal == ctx.getSetDecl() && + isNSObjectOrAnyHashable(ctx, typeArgs[0])))) { typeArgs = {}; } + + // Use the proper upper id bound for Dictionaries with + // upper-bounded keys. + else if (swiftNominal == ctx.getDictionaryDecl() && + isNSObjectOrAnyHashable(ctx, typeArgs[0])) { + if (Module *M = ctx.getLoadedModule(ctx.Id_Foundation)) { + if (!NSCopyingType) { + UnqualifiedLookup lookup(ctx.getIdentifier("NSCopying"), M, nullptr); + auto type = lookup.getSingleTypeResult(); + if (type && isa(type)) { + NSCopyingType = type->getDeclaredType(); + } else { + NSCopyingType = Type(); + } + } + if (*NSCopyingType) { + rewrittenArgsBuf[0] = *NSCopyingType; + rewrittenArgsBuf[1] = typeArgs[1]; + typeArgs = rewrittenArgsBuf; + } + } + } // Print the class type. SmallString<32> objcNameScratch; @@ -1119,12 +1161,17 @@ class ObjCPrinter : private DeclVisitor, // Use the type as bridged to Objective-C unless the element type is itself // an imported type or a collection. const StructDecl *SD = ty->getStructOrBoundGenericStruct(); - if (SD != ctx.getArrayDecl() && + if (ty->isAny()) { + ty = ctx.getProtocol(KnownProtocolKind::AnyObject) + ->getDeclaredType(); + } else if (SD != ctx.getArrayDecl() && SD != ctx.getDictionaryDecl() && SD != ctx.getSetDecl() && !isSwiftNewtype(SD)) { ty = *ctx.getBridgedToObjC(&M, ty, /*resolver*/nullptr); } + + assert(ty && "unknown bridged type"); print(ty, None); } diff --git a/lib/SIL/SILType.cpp b/lib/SIL/SILType.cpp index 33f529cf9b408..932749ad42f01 100644 --- a/lib/SIL/SILType.cpp +++ b/lib/SIL/SILType.cpp @@ -465,8 +465,8 @@ static bool isBridgedErrorClass(SILModule &M, t = archetypeType->getSuperclass(); // NSError (TODO: and CFError) can be bridged. - auto errorType = M.Types.getNSErrorType(); - if (t && errorType && t->isEqual(errorType)) { + auto nsErrorType = M.Types.getNSErrorType(); + if (t && nsErrorType && nsErrorType->isExactSuperclassOf(t, nullptr)) { return true; } diff --git a/lib/SILGen/SILGen.cpp b/lib/SILGen/SILGen.cpp index 4846cfb3479e2..0996993e5fc93 100644 --- a/lib/SILGen/SILGen.cpp +++ b/lib/SILGen/SILGen.cpp @@ -283,6 +283,83 @@ SILGenModule::getConformanceToObjectiveCBridgeable(SILLocation loc, Type type) { return nullptr; } +ProtocolDecl *SILGenModule::getBridgedStoredNSError(SILLocation loc) { + if (BridgedStoredNSError) + return *BridgedStoredNSError; + + // Find the _BridgedStoredNSError protocol. + auto &ctx = getASTContext(); + auto proto = ctx.getProtocol(KnownProtocolKind::BridgedStoredNSError); + BridgedStoredNSError = proto; + return proto; +} + +VarDecl *SILGenModule::getNSErrorRequirement(SILLocation loc) { + if (NSErrorRequirement) + return *NSErrorRequirement; + + // Find the _BridgedStoredNSError protocol. + auto proto = getBridgedStoredNSError(loc); + if (!proto) { + NSErrorRequirement = nullptr; + return nullptr; + } + + // Look for _nsError. + auto &ctx = getASTContext(); + VarDecl *found = nullptr; + for (auto member : proto->lookupDirect(ctx.Id_nsError, true)) { + if (auto var = dyn_cast(member)) { + found = var; + break; + } + } + + NSErrorRequirement = found; + return found; +} + +ProtocolConformance * +SILGenModule::getConformanceToBridgedStoredNSError(SILLocation loc, Type type) { + auto proto = getBridgedStoredNSError(loc); + if (!proto) return nullptr; + + // Find the conformance to _BridgedStoredNSError. + auto result = SwiftModule->lookupConformance(type, proto, nullptr); + if (result) return result->getConcrete(); + return nullptr; +} + +ProtocolConformance *SILGenModule::getNSErrorConformanceToError() { + if (NSErrorConformanceToError) + return *NSErrorConformanceToError; + + auto &ctx = getASTContext(); + auto nsError = ctx.getNSErrorDecl(); + if (!nsError) { + NSErrorConformanceToError = nullptr; + return nullptr; + } + + auto error = ctx.getErrorDecl(); + if (!error) { + NSErrorConformanceToError = nullptr; + return nullptr; + } + + auto conformance = + SwiftModule->lookupConformance(nsError->getDeclaredInterfaceType(), + cast(error), + nullptr); + + if (conformance && conformance->isConcrete()) + NSErrorConformanceToError = conformance->getConcrete(); + else + NSErrorConformanceToError = nullptr; + return *NSErrorConformanceToError; +} + + SILFunction *SILGenModule::emitTopLevelFunction(SILLocation Loc) { ASTContext &C = M.getASTContext(); auto extInfo = SILFunctionType::ExtInfo() diff --git a/lib/SILGen/SILGen.h b/lib/SILGen/SILGen.h index d4b294e1afe7f..88809359c100e 100644 --- a/lib/SILGen/SILGen.h +++ b/lib/SILGen/SILGen.h @@ -129,6 +129,11 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor { Optional UnconditionallyBridgeFromObjectiveCRequirement; Optional BridgedObjectiveCType; + Optional BridgedStoredNSError; + Optional NSErrorRequirement; + + Optional NSErrorConformanceToError; + public: SILGenModule(SILModule &M, Module *SM, bool makeModuleFragile); ~SILGenModule(); @@ -377,6 +382,20 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor { ProtocolConformance *getConformanceToObjectiveCBridgeable(SILLocation loc, Type type); + /// Retrieve the _BridgedStoredNSError protocol definition. + ProtocolDecl *getBridgedStoredNSError(SILLocation loc); + + /// Retrieve the _BridgedStoredNSError._nsError requirement. + VarDecl *getNSErrorRequirement(SILLocation loc); + + /// Find the conformance of the given Swift type to the + /// _BridgedStoredNSError protocol. + ProtocolConformance *getConformanceToBridgedStoredNSError(SILLocation loc, + Type type); + + /// Retrieve the conformance of NSError to the Error protocol. + ProtocolConformance *getNSErrorConformanceToError(); + /// Report a diagnostic. template InFlightDiagnostic diagnose(SourceLoc loc, Diag diag, diff --git a/lib/SILGen/SILGenConvert.cpp b/lib/SILGen/SILGenConvert.cpp index aefd04b7aea71..3ab4dd3d46791 100644 --- a/lib/SILGen/SILGenConvert.cpp +++ b/lib/SILGen/SILGenConvert.cpp @@ -450,11 +450,159 @@ ManagedValue SILGenFunction::emitExistentialErasure( const TypeLowering &existentialTL, ArrayRef conformances, SGFContext C, - llvm::function_ref F) { + llvm::function_ref F, + bool allowEmbeddedNSError) { // Mark the needed conformances as used. for (auto conformance : conformances) SGM.useConformance(conformance); + // If we're erasing to the 'Error' type, we might be able to get an NSError + // representation more efficiently. + auto &ctx = getASTContext(); + auto nsError = ctx.getNSErrorDecl(); + if (allowEmbeddedNSError && nsError && + existentialTL.getSemanticType().getSwiftRValueType()->getAnyNominal() == + ctx.getErrorDecl()) { + // Check whether the concrete type conforms to the _BridgedStoredNSError + // protocol. In that case, call the _nsError witness getter to extract the + // NSError directly. + auto conformance = + SGM.getConformanceToBridgedStoredNSError(loc, concreteFormalType); + + CanType nsErrorType = + nsError->getDeclaredInterfaceType()->getCanonicalType(); + + ProtocolConformanceRef nsErrorConformances[1] = { + ProtocolConformanceRef(SGM.getNSErrorConformanceToError()) + }; + + if (conformance && nsError && SGM.getNSErrorConformanceToError()) { + if (auto witness = + conformance->getWitness(SGM.getNSErrorRequirement(loc), nullptr)) { + // Create a reference to the getter witness. + SILDeclRef getter = + getGetterDeclRef(cast(witness.getDecl()), + /*isDirectAccessorUse=*/true); + + // Compute the substitutions. + ArrayRef substitutions = + concreteFormalType->gatherAllSubstitutions( + SGM.SwiftModule, nullptr); + + // Emit the erasure, through the getter to _nsError. + return emitExistentialErasure( + loc, nsErrorType, + getTypeLowering(nsErrorType), + existentialTL, + ctx.AllocateCopy(nsErrorConformances), + C, + [&](SGFContext innerC) -> ManagedValue { + // Call the getter. + return emitGetAccessor(loc, getter, substitutions, + ArgumentSource(loc, + RValue(*this, loc, + concreteFormalType, + F(SGFContext()))), + /*isSuper=*/false, + /*isDirectAccessorUse=*/true, + RValue(), innerC) + .getAsSingleValue(*this, loc); + }); + } + } + + // Check whether the concrete type is an archetype. If so, call the + // _getEmbeddedNSError() witness to try to dig out the embedded NSError. + if (auto archetypeType = concreteFormalType->getAs()) { + if (std::find(archetypeType->getConformsTo().begin(), + archetypeType->getConformsTo().end(), + ctx.getErrorDecl()) + != archetypeType->getConformsTo().end()) { + auto contBB = createBasicBlock(); + auto isNotPresentBB = createBasicBlock(); + auto isPresentBB = createBasicBlock(); + + SILValue existentialResult = + contBB->createBBArg(existentialTL.getLoweredType()); + + ProtocolConformanceRef trivialErrorConformances[1] = { + ProtocolConformanceRef(ctx.getErrorDecl()) + }; + + Substitution substitutions[1] = { + Substitution(concreteFormalType, + ctx.AllocateCopy(trivialErrorConformances)) + }; + + // Call swift_stdlib_getErrorEmbeddedNSError to attempt to extract an + // NSError from the value. + ManagedValue concreteValue = F(SGFContext()); + ManagedValue potentialNSError = + emitApplyOfLibraryIntrinsic(loc, + SGM.getGetErrorEmbeddedNSError(loc), + ctx.AllocateCopy(substitutions), + { concreteValue }, + SGFContext()) + .getAsSingleValue(*this, loc); + + // Check whether we got an NSError back. + SILValue hasNSError = + emitDoesOptionalHaveValue(loc, potentialNSError.getValue()); + + B.createCondBranch(loc, hasNSError, isPresentBB, isNotPresentBB); + + // If we did get an NSError, emit the existential erasure from that + // NSError. + B.emitBlock(isPresentBB); + SILValue branchArg; + { + // Don't allow cleanups to escape the conditional block. + FullExpr presentScope(Cleanups, CleanupLocation::get(loc)); + + // Emit the existential erasure from the NSError. + branchArg = emitExistentialErasure( + loc, nsErrorType, + getTypeLowering(nsErrorType), + existentialTL, + ctx.AllocateCopy(nsErrorConformances), + C, + [&](SGFContext innerC) -> ManagedValue { + // Pull the NSError object out of the optional result. + auto &inputTL = getTypeLowering(potentialNSError.getType()); + auto nsErrorValue = + emitUncheckedGetOptionalValueFrom(loc, potentialNSError, + inputTL); + + + // Perform an unchecked cast down to NSError, because it was typed + // as 'AnyObject' for layering reasons. + return ManagedValue(B.createUncheckedRefCast( + loc, + nsErrorValue.getValue(), + getLoweredType(nsErrorType)), + nsErrorValue.getCleanup()); + + }).forward(*this); + } + B.createBranch(loc, contBB, branchArg); + + // If we did not get an NSError, just directly emit the existential + // (recursively). + B.emitBlock(isNotPresentBB); + branchArg = emitExistentialErasure(loc, concreteFormalType, concreteTL, + existentialTL, conformances, + SGFContext(), F, + /*allowEmbeddedNSError=*/false) + .forward(*this); + B.createBranch(loc, contBB, branchArg); + + // Continue. + B.emitBlock(contBB); + return emitManagedRValueWithCleanup(existentialResult, existentialTL); + } + } + } + switch (existentialTL.getLoweredType().getObjectType() .getPreferredExistentialRepresentation(SGM.M, concreteFormalType)) { case ExistentialRepresentation::None: diff --git a/lib/SILGen/SILGenFunction.h b/lib/SILGen/SILGenFunction.h index 5a3f69f019f42..6d6cadd7869b6 100644 --- a/lib/SILGen/SILGenFunction.h +++ b/lib/SILGen/SILGenFunction.h @@ -944,7 +944,8 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction const TypeLowering &existentialTL, ArrayRef conformances, SGFContext C, - llvm::function_ref F); + llvm::function_ref F, + bool allowEmbeddedNSError = true); //===--------------------------------------------------------------------===// // Recursive entry points diff --git a/lib/Sema/CSDiag.cpp b/lib/Sema/CSDiag.cpp index f5387a7133950..1c0960f026bd4 100644 --- a/lib/Sema/CSDiag.cpp +++ b/lib/Sema/CSDiag.cpp @@ -3593,6 +3593,62 @@ addTypeCoerceFixit(InFlightDiagnostic &diag, ConstraintSystem *CS, return false; } +/// Try to diagnose common errors involving implicitly non-escaping parameters +/// of function type, giving more specific and simpler diagnostics, attaching +/// notes on the parameter, and offering fixits to insert @escaping. Returns +/// true if it detects and issues an error, false if it does nothing. +static bool tryDiagnoseNonEscapingParameterToEscaping(Expr *expr, Type srcType, + Type dstType, + ConstraintSystem *CS) { + assert(expr && CS); + // Need to be referencing a parameter of function type + auto declRef = dyn_cast(expr); + if (!declRef || !isa(declRef->getDecl()) || + !declRef->getType()->is()) + return false; + + // Must be from non-escaping function to escaping function + auto srcFT = srcType->getAs(); + auto destFT = dstType->getAs(); + if (!srcFT || !destFT || !srcFT->isNoEscape() || destFT->isNoEscape()) + return false; + + // Function types must be equivalent modulo @escaping, @convention, etc. + if (!destFT->isEqual(srcFT->withExtInfo(destFT->getExtInfo()))) + return false; + + // Pick a specific diagnostic for the specific use + auto paramDecl = cast(declRef->getDecl()); + switch (CS->getContextualTypePurpose()) { + case CTP_CallArgument: + CS->TC.diagnose(declRef->getLoc(), diag::passing_noescape_to_escaping, + paramDecl->getName()); + break; + case CTP_AssignSource: + CS->TC.diagnose(declRef->getLoc(), diag::assigning_noescape_to_escaping, + paramDecl->getName()); + break; + + default: + CS->TC.diagnose(declRef->getLoc(), diag::general_noescape_to_escaping, + paramDecl->getName()); + break; + } + + // Give a note and fixit + InFlightDiagnostic note = CS->TC.diagnose( + paramDecl->getLoc(), srcFT->isAutoClosure() ? diag::noescape_autoclosure + : diag::noescape_parameter, + paramDecl->getName()); + + if (!srcFT->isAutoClosure()) { + note.fixItInsert(paramDecl->getTypeLoc().getSourceRange().Start, + "@escaping "); + } // TODO: add in a fixit for autoclosure + + return true; +} + bool FailureDiagnosis::diagnoseContextualConversionError() { // If the constraint system has a contextual type, then we can test to see if // this is the problem that prevents us from solving the system. @@ -3677,7 +3733,7 @@ bool FailureDiagnosis::diagnoseContextualConversionError() { diagIDProtocol = diag::cannot_convert_to_return_type_protocol; nilDiag = diag::cannot_convert_to_return_type_nil; break; - case CTP_ThrowStmt: + case CTP_ThrowStmt: { if (isa(expr->getValueProvidingExpr())) { diagnose(expr->getLoc(), diag::cannot_throw_nil); return true; @@ -3686,14 +3742,42 @@ bool FailureDiagnosis::diagnoseContextualConversionError() { if (isUnresolvedOrTypeVarType(exprType) || exprType->isEqual(contextualType)) return false; - + + // If we tried to throw the error code of an error type, suggest object + // construction. + auto &TC = CS->getTypeChecker(); + if (auto errorCodeProtocol = + TC.Context.getProtocol(KnownProtocolKind::ErrorCodeProtocol)) { + ProtocolConformance *conformance = nullptr; + if (TC.conformsToProtocol(expr->getType(), errorCodeProtocol, CS->DC, + ConformanceCheckFlags::InExpression, + &conformance) && + conformance) { + Type errorCodeType = expr->getType(); + Type errorType = + ProtocolConformance::getTypeWitnessByName(errorCodeType, conformance, + TC.Context.Id_ErrorType, + &TC)->getCanonicalType(); + if (errorType) { + auto diag = diagnose(expr->getLoc(), diag::cannot_throw_error_code, + errorCodeType, errorType); + if (auto unresolvedDot = dyn_cast(expr)) { + diag.fixItInsert(unresolvedDot->getDotLoc(), "("); + diag.fixItInsertAfter(unresolvedDot->getEndLoc(), ")"); + } + return true; + } + } + } + // The conversion destination of throw is always ErrorType (at the moment) // if this ever expands, this should be a specific form like () is for // return. diagnose(expr->getLoc(), diag::cannot_convert_thrown_type, exprType) .highlight(expr->getSourceRange()); return true; - + } + case CTP_EnumCaseRawValue: diagID = diag::cannot_convert_raw_initializer_value; diagIDProtocol = diag::cannot_convert_raw_initializer_value; @@ -3827,6 +3911,11 @@ bool FailureDiagnosis::diagnoseContextualConversionError() { } } + // Try for better/more specific diagnostics for non-escaping to @escaping + if (tryDiagnoseNonEscapingParameterToEscaping(expr, exprType, contextualType, + CS)) + return true; + // When complaining about conversion to a protocol type, complain about // conformance instead of "conversion". if (contextualType->is() || diff --git a/stdlib/private/StdlibCollectionUnittest/LoggingWrappers.swift.gyb b/stdlib/private/StdlibCollectionUnittest/LoggingWrappers.swift.gyb index 94d11e5e8e1cf..d5548338abb25 100644 --- a/stdlib/private/StdlibCollectionUnittest/LoggingWrappers.swift.gyb +++ b/stdlib/private/StdlibCollectionUnittest/LoggingWrappers.swift.gyb @@ -12,6 +12,7 @@ %{ from gyb_stdlib_support import TRAVERSALS, collectionForTraversal +from gyb_stdlib_unittest_support import TRACE, stackTrace, trace }% import StdlibUnittest @@ -666,12 +667,7 @@ public struct ${Self}< //===----------------------------------------------------------------------===// public func expectCustomizable( - _: T, _ counters: TypeIndexed, - //===--- TRACE boilerplate ----------------------------------------------===// - _ message: @autoclosure () -> String = "", - showFrame: Bool = true, - stackTrace: SourceLocStack = SourceLocStack(), - file: String = #file, line: UInt = #line + _: T, _ counters: TypeIndexed, ${TRACE} ) where T : LoggingType, T.Base : Wrapper, T.Base : LoggingType, @@ -683,12 +679,7 @@ public func expectCustomizable( } public func expectNotCustomizable( - _: T, _ counters: TypeIndexed, - //===--- TRACE boilerplate ----------------------------------------------===// - _ message: @autoclosure () -> String = "", - showFrame: Bool = true, - stackTrace: SourceLocStack = SourceLocStack(), - file: String = #file, line: UInt = #line + _: T, _ counters: TypeIndexed, ${TRACE} ) where T : LoggingType, T.Base : Wrapper, T.Base : LoggingType, diff --git a/stdlib/public/SDK/AppKit/AppKit.swift b/stdlib/public/SDK/AppKit/AppKit.swift index 85610ea62bdef..8309c3f5231f0 100644 --- a/stdlib/public/SDK/AppKit/AppKit.swift +++ b/stdlib/public/SDK/AppKit/AppKit.swift @@ -56,7 +56,7 @@ public extension NSGradient { self.init( colors: objects.map { $0.0 }, atLocations: objects.map { $0.1 }, - colorSpace: NSColorSpace.genericRGB()) + colorSpace: NSColorSpace.genericRGB) } } diff --git a/stdlib/public/SDK/CMakeLists.txt b/stdlib/public/SDK/CMakeLists.txt index a76cc2fd52ff5..0cbd918e31878 100644 --- a/stdlib/public/SDK/CMakeLists.txt +++ b/stdlib/public/SDK/CMakeLists.txt @@ -31,6 +31,7 @@ add_subdirectory(IOKit) add_subdirectory(Intents) add_subdirectory(ObjectiveC) add_subdirectory(OpenCL) +add_subdirectory(os) add_subdirectory(Photos) add_subdirectory(SafariServices) add_subdirectory(SceneKit) diff --git a/stdlib/public/SDK/CoreGraphics/CMakeLists.txt b/stdlib/public/SDK/CoreGraphics/CMakeLists.txt index fd1c5962529a0..ec2a4ac7a26fa 100644 --- a/stdlib/public/SDK/CoreGraphics/CMakeLists.txt +++ b/stdlib/public/SDK/CoreGraphics/CMakeLists.txt @@ -1,6 +1,7 @@ add_swift_library(swiftCoreGraphics ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY CoreGraphics.swift CGFloat.swift.gyb + Private.swift # rdar://problem/20891746 # SWIFT_COMPILE_FLAGS ${STDLIB_SIL_SERIALIZE_ALL} SWIFT_MODULE_DEPENDS ObjectiveC Dispatch Darwin diff --git a/stdlib/public/SDK/CoreGraphics/CoreGraphics.swift b/stdlib/public/SDK/CoreGraphics/CoreGraphics.swift index 9d7f79ea20c05..898ca6094a203 100644 --- a/stdlib/public/SDK/CoreGraphics/CoreGraphics.swift +++ b/stdlib/public/SDK/CoreGraphics/CoreGraphics.swift @@ -13,6 +13,180 @@ @_exported import CoreGraphics import Darwin +//===----------------------------------------------------------------------===// +// CGAffineTransform +//===----------------------------------------------------------------------===// + +extension CGAffineTransform: Equatable {} +public func ==(lhs: CGAffineTransform, rhs: CGAffineTransform) -> Bool { + return lhs.__equalTo(rhs) +} + +//===----------------------------------------------------------------------===// +// CGColor +//===----------------------------------------------------------------------===// + +extension CGColor { + @available(OSX 10.3, iOS 2.0, *) + public var components: [CGFloat]? { + guard let pointer = self.__unsafeComponents else { return nil } + let buffer = UnsafeBufferPointer(start: pointer, count: self.numberOfComponents) + return Array(buffer) + } + +#if os(macOS) + public class var white: CGColor + { return CGColor.__constantColor(for: CGColor.__whiteColorName)! } + + public class var black: CGColor + { return CGColor.__constantColor(for: CGColor.__blackColorName)! } + + public class var clear: CGColor + { return CGColor.__constantColor(for: CGColor.__clearColorName)! } +#endif +} + +extension CGColor: Equatable {} +public func ==(lhs: CGColor, rhs: CGColor) -> Bool { + return lhs.__equalTo(rhs) +} + + +//===----------------------------------------------------------------------===// +// CGColorSpace +//===----------------------------------------------------------------------===// + +extension CGColorSpace { + public var colorTable: [UInt8]? { + guard self.model == .indexed else { return nil } + var table = [UInt8](repeating: 0, count: self.__colorTableCount) + self.__unsafeGetColorTable(&table) + return table + } +} + +//===----------------------------------------------------------------------===// +// CGContext +//===----------------------------------------------------------------------===// + +extension CGContext { + + public func setLineDash(phase: CGFloat, lengths: [CGFloat]) { + self.__setLineDash(phase: phase, lengths: lengths, count: lengths.count) + } + + public func move(to point: CGPoint) { + self.__moveTo(x: point.x, y: point.y) + } + + public func addLine(to point: CGPoint) { + self.__addLineTo(x: point.x, y: point.y) + } + + public func addCurve(to end: CGPoint, control1: CGPoint, control2: CGPoint) { + self.__addCurveTo(cp1x: control1.x, cp1y: control1.y, + cp2x: control2.x, cp2y: control2.y, endingAtX: end.x, y: end.y) + } + + public func addQuadCurve(to end: CGPoint, control: CGPoint) { + self.__addQuadCurveTo(cpx: control.x, cpy: control.y, + endingAtX: end.x, y: end.y) + } + + public func addRects(_ rects: [CGRect]) { + self.__addRects(rects, count: rects.count) + } + + public func addLines(between points: [CGPoint]) { + self.__addLines(between: points, count: points.count) + } + + public func addArc(center: CGPoint, radius: CGFloat, startAngle: CGFloat, + endAngle: CGFloat, clockwise: Bool) { + self.__addArc(centerX: center.x, y: center.y, radius: radius, + startAngle: startAngle, endAngle: endAngle, clockwise: clockwise ? 1 : 0) + } + + public func addArc(tangent1End: CGPoint, tangent2End: CGPoint, + radius: CGFloat) { + self.__addArc(x1: tangent1End.x, y1: tangent1End.y, + x2: tangent2End.x, y2: tangent2End.y, radius: radius) + } + + /// Fills the current path using the specified rule (winding by default). + /// + /// Any open subpath is implicitly closed. + public func fillPath(using rule: CGPathFillRule = .winding) { + switch rule { + case .winding: self.__fillPath() + case .evenOdd: self.__eoFillPath() + } + } + + /// Intersects the current path with the current clipping region and uses the + /// result as the new clipping region for subsequent drawing. + /// + /// Uses the specified fill rule (winding by default) to determine which + /// areas to treat as the interior of the clipping region. When evaluating + /// the path, any open subpath is implicitly closed. + public func clip(using rule: CGPathFillRule = .winding) { + switch rule { + case .winding: self.__clip() + case .evenOdd: self.__eoClip() + } + } + + public func fill(_ rects: [CGRect]) { + self.__fill(rects, count: rects.count) + } + + public func strokeLineSegments(between points: [CGPoint]) { + self.__strokeLineSegments(between: points, count: points.count) + } + + public func clip(to rects: [CGRect]) { + self.__clip(to: rects, count: rects.count) + } + + public func draw(_ image: CGImage, in rect: CGRect, byTiling: Bool = false) { + if byTiling { + self.__draw(in: rect, byTiling: image) + } else { + self.__draw(in: rect, image: image) + } + } + + public var textPosition: CGPoint { + get { return self.__textPosition } + set { self.__setTextPosition(x: newValue.x, y: newValue.y) } + } + + public func showGlyphs(_ glyphs: [CGGlyph], at positions: [CGPoint]) { + precondition(glyphs.count == positions.count) + self.__showGlyphs(glyphs, atPositions: positions, count: glyphs.count) + } + +} + +//===----------------------------------------------------------------------===// +// CGDataProvider +//===----------------------------------------------------------------------===// + +// TODO: replace init(UnsafePointer) with init(String) +// blocked on rdar://problem/27444567 + +//===----------------------------------------------------------------------===// +// CGDirectDisplay +//===----------------------------------------------------------------------===// + +#if os(macOS) +public func CGGetLastMouseDelta() -> (x: Int32, y: Int32) { + var pair: (x: Int32, y: Int32) = (0, 0) + __CGGetLastMouseDelta(&pair.x, &pair.y) + return pair +} +#endif + //===----------------------------------------------------------------------===// // CGGeometry //===----------------------------------------------------------------------===// @@ -32,6 +206,15 @@ public extension CGPoint { init(x: Double, y: Double) { self.init(x: CGFloat(x), y: CGFloat(y)) } + + init?(dictionaryRepresentation dict: CFDictionary) { + var point = CGPoint() + if CGPoint.__setFromDictionaryRepresentation(dict, &point) { + self = point + } else { + return nil + } + } } extension CGPoint : CustomReflectable, CustomPlaygroundQuickLookable { @@ -71,6 +254,15 @@ public extension CGSize { init(width: Double, height: Double) { self.init(width: CGFloat(width), height: CGFloat(height)) } + + init?(dictionaryRepresentation dict: CFDictionary) { + var size = CGSize() + if CGSize.__setFromDictionaryRepresentation(dict, &size) { + self = size + } else { + return nil + } + } } extension CGSize : CustomReflectable, CustomPlaygroundQuickLookable { @@ -146,13 +338,22 @@ public extension CGRect { size: CGSize(width: width, height: height)) } + init?(dictionaryRepresentation dict: CFDictionary) { + var rect = CGRect() + if CGRect.__setFromDictionaryRepresentation(dict, &rect) { + self = rect + } else { + return nil + } + } + @_transparent // @fragile func divided(atDistance: CGFloat, from fromEdge: CGRectEdge) -> (slice: CGRect, remainder: CGRect) { var slice = CGRect.zero var remainder = CGRect.zero - divided(slice: &slice, remainder: &remainder, atDistance: atDistance, + self.__divided(slice: &slice, remainder: &remainder, atDistance: atDistance, from: fromEdge) return (slice, remainder) } @@ -192,3 +393,165 @@ extension CGAffineTransform { } } +//===----------------------------------------------------------------------===// +// CGImage +//===----------------------------------------------------------------------===// + +extension CGImage { + public func copy(maskingColorComponents components: [CGFloat]) -> CGImage? { + return self.__copy(maskingColorComponents: UnsafePointer(components)) + } +} + +//===----------------------------------------------------------------------===// +// CGLayer +//===----------------------------------------------------------------------===// + +// TODO: remove auxiliaryInfo parameter from CGLayer.init, +// or at least give it a default value (empty/nil) +// blocked on rdar://problem/27444567 +extension CGContext { + public func draw(_ layer: CGLayer, in rect: CGRect) { + self.__draw(in: rect, layer: layer) + } + + public func draw(_ layer: CGLayer, at point: CGPoint) { + self.__draw(at: point, layer: layer) + } +} + +//===----------------------------------------------------------------------===// +// CGPath & CGMutablePath +//===----------------------------------------------------------------------===// + +// TODO: Make this a nested type (CGPath.FillRule) +public enum CGPathFillRule: Int { + /// Nonzero winding number fill rule. + /// + /// This rule plots a ray from the interior of the region to be evaluated + /// toward the bounds of the drawing, and sums the closed path elements + /// that the ray crosses: +1 for counterclockwise paths, -1 for clockwise. + /// If the sum is zero, the region is left empty; if the sum is nonzero, + /// the region is filled. + case winding + + /// Even-Odd fill rule. + /// + /// This rule plots a ray from the interior of the region to be evaluated + /// toward the bounds of the drawing, and sums the closed path elements + /// that the ray crosses. + /// If the sum is an even numner, the region is left empty; if the sum is + /// an odd number, the region is filled. + case evenOdd +} + +extension CGPath { + public func copy(dashingWithPhase phase: CGFloat, lengths: [CGFloat], + transform: CGAffineTransform = .identity) -> CGPath { + return CGPath(__byDashing: self, transform: [transform], + phase: phase, lengths: lengths, count: lengths.count)! + // force unwrap / non-optional return ok: underlying func returns nil + // only on bad input that we've made impossible (self and transform) + } + + public func copy(strokingWithWidth lineWidth: CGFloat, lineCap: CGLineCap, + lineJoin: CGLineJoin, miterLimit: CGFloat, + transform: CGAffineTransform = .identity) -> CGPath { + return CGPath(__byStroking: self, transform: [transform], + lineWidth: lineWidth, lineCap: lineCap, lineJoin: lineJoin, + miterLimit: miterLimit)! + // force unwrap / non-optional return ok: underlying func returns nil + // only on bad input that we've made impossible (self and transform) + } + + public func contains(_ point: CGPoint, using rule: CGPathFillRule = .winding, + transform: CGAffineTransform = .identity) -> Bool { + return self.__containsPoint(transform: [transform], + point: point, eoFill: (rule == .evenOdd)) + } +} + +extension CGPath: Equatable {} +public func ==(lhs: CGPath, rhs: CGPath) -> Bool { + return lhs.__equalTo(rhs) +} + +extension CGMutablePath { + + public func addRoundedRect(in rect: CGRect, cornerWidth: CGFloat, + cornerHeight: CGFloat, transform: CGAffineTransform = .identity) { + self.__addRoundedRect(transform: [transform], rect: rect, + cornerWidth: cornerWidth, cornerHeight: cornerHeight) + } + + public func move(to point: CGPoint, + transform: CGAffineTransform = .identity) { + self.__moveTo(transform: [transform], x: point.x, y: point.y) + } + + public func addLine(to point: CGPoint, + transform: CGAffineTransform = .identity) { + self.__addLineTo(transform: [transform], x: point.x, y: point.y) + } + + public func addQuadCurve(to end: CGPoint, control: CGPoint, + transform: CGAffineTransform = .identity) { + self.__addQuadCurve(transform: [transform], cpx: control.x, cpy: control.y, + endingAtX: end.x, y: end.y) + } + + public func addCurve(to end: CGPoint, control1: CGPoint, control2: CGPoint, + transform: CGAffineTransform = .identity) { + self.__addCurve(transform: [transform], cp1x: control1.x, cp1y: control1.y, + cp2x: control2.x, cp2y: control2.y, endingAtX: end.x, y: end.y) + } + + public func addRect(_ rect: CGRect, + transform: CGAffineTransform = .identity) { + self.__addRect(transform: [transform], rect: rect) + } + + public func addRects(_ rects: [CGRect], + transform: CGAffineTransform = .identity) { + self.__addRects(transform: [transform], rects: rects, count: rects.count) + } + + public func addLines(between points: [CGPoint], + transform: CGAffineTransform = .identity) { + self.__addLines(transform: [transform], + between: points, count: points.count) + } + + public func addEllipse(in rect: CGRect, + transform: CGAffineTransform = .identity) { + self.__addEllipse(transform: [transform], rect: rect) + } + + public func addRelativeArc(center: CGPoint, radius: CGFloat, + startAngle: CGFloat, delta: CGFloat, + transform: CGAffineTransform = .identity) { + self.__addRelativeArc(transform: [transform], x: center.x, y: center.y, + radius: radius, startAngle: startAngle, delta: delta) + } + + public func addArc(center: CGPoint, radius: CGFloat, + startAngle: CGFloat, endAngle: CGFloat, clockwise: Bool, + transform: CGAffineTransform = .identity) { + self.__addArc(transform: [transform], x: center.x, y: center.y, + radius: radius, startAngle: startAngle, endAngle: endAngle, + clockwise: clockwise) + } + + public func addArc(tangent1End: CGPoint, tangent2End: CGPoint, + radius: CGFloat, transform: CGAffineTransform = .identity) { + self.__addArc(transform: [transform], x1: tangent1End.x, y1: tangent1End.y, + x2: tangent2End.x, y2: tangent2End.y, radius: radius) + } + + public func addPath(_ path: CGPath, + transform: CGAffineTransform = .identity) { + self.__addPath(transform: [transform], path: path) + } + +} + diff --git a/stdlib/public/SDK/CoreGraphics/Private.swift b/stdlib/public/SDK/CoreGraphics/Private.swift new file mode 100644 index 0000000000000..ed25fab83f0c7 --- /dev/null +++ b/stdlib/public/SDK/CoreGraphics/Private.swift @@ -0,0 +1,229 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See http://swift.org/LICENSE.txt for license information +// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +// Redeclarations of all SwiftPrivate symbols with appropriate markup, +// so that tools can help with migration + +// @available(*, unavailable, renamed:"DispatchQueue.init(label:attributes:target:)") +@available(*, unavailable, message:"Use == instead") +public func CGAffineTransformEqualToTransform(_ t1: CGAffineTransform, _ t2: CGAffineTransform) -> Bool + { fatalError() } + +@available(*, unavailable, message:"Use class var white/black/clear instead") +public func CGColorGetConstantColor(_ colorName: CFString?) -> CGColor? + { fatalError() } + +@available(*, unavailable, message:"Use == instead") +public func CGColorEqualToColor(_ color1: CGColor?, _ color2: CGColor?) -> Bool + { fatalError() } + +@available(*, unavailable, renamed:"getter:CGColor.components(self:)") +public func CGColorGetComponents(_ color: CGColor?) -> UnsafePointer + { fatalError() } + +@available(*, unavailable, message:"Use colorTable.count instead") +public func CGColorSpaceGetColorTableCount(_ space: CGColorSpace?) -> Int + { fatalError() } + +@available(*, unavailable, renamed:"CGColorSpace.colorTable(self:_:)") +public func CGColorSpaceGetColorTable(_ space: CGColorSpace?, _ table: UnsafeMutablePointer) + { fatalError() } + +@available(*, unavailable, message:"Use setLineDash(self:phase:lengths:)") +public func CGContextSetLineDash(_ c: CGContext?, _ phase: CGFloat, _ lengths: UnsafePointer, _ count: Int) + { fatalError() } + +@available(*, unavailable, message:"Use move(to:) instead") +public func CGContextMoveToPoint(_ c: CGContext?, _ x: CGFloat, _ y: CGFloat) + { fatalError() } + +@available(*, unavailable, message:"Use addLine(to:) instead") +public func CGContextAddLineToPoint(_ c: CGContext?, _ x: CGFloat, _ y: CGFloat) + { fatalError() } + +@available(*, unavailable, message:"Use addCurve(to:control1:control2:) instead") +public func CGContextAddCurveToPoint(_ c: CGContext?, _ cp1x: CGFloat, _ cp1y: CGFloat, _ cp2x: CGFloat, _ cp2y: CGFloat, _ x: CGFloat, _ y: CGFloat) + { fatalError() } + +@available(*, unavailable, message:"Use addQuadCurve(to:control:)") +public func CGContextAddQuadCurveToPoint(_ c: CGContext?, _ cpx: CGFloat, _ cpy: CGFloat, _ x: CGFloat, _ y: CGFloat) + { fatalError() } + +@available(*, unavailable, message:"Use addRects(_:)") +public func CGContextAddRects(_ c: CGContext?, _ rects: UnsafePointer, _ count: Int) + { fatalError() } + +@available(*, unavailable, message:"Use addLines(between:)") +public func CGContextAddLines(_ c: CGContext?, _ points: UnsafePointer, _ count: Int) + { fatalError() } + +@available(*, unavailable, message:"Use addArc(center:radius:startAngle:endAngle:clockwise:)") +public func CGContextAddArc(_ c: CGContext?, _ x: CGFloat, _ y: CGFloat, _ radius: CGFloat, _ startAngle: CGFloat, _ endAngle: CGFloat, _ clockwise: Int32) + { fatalError() } + +@available(*, unavailable, message:"Use addArc(self:x1:y1:x2:y2:radius:)") +public func CGContextAddArcToPoint(_ c: CGContext?, _ x1: CGFloat, _ y1: CGFloat, _ x2: CGFloat, _ y2: CGFloat, _ radius: CGFloat) + { fatalError() } + +@available(*, unavailable, message:"Use fill(self:_:count:)") +public func CGContextFillRects(_ c: CGContext?, _ rects: UnsafePointer, _ count: Int) + { fatalError() } + +@available(*, unavailable, message:"Use strokeLineSegments(self:between:count:)") +public func CGContextStrokeLineSegments(_ c: CGContext?, _ points: UnsafePointer, _ count: Int) + { fatalError() } + +@available(*, unavailable, message:"Use clip(to:)") +public func CGContextClipToRects(_ c: CGContext?, _ rects: UnsafePointer, _ count: Int) + { fatalError() } + +@available(*, unavailable, message:"Use draw(_:in:)") +public func CGContextDrawImage(_ c: CGContext?, _ rect: CGRect, _ image: CGImage?) + { fatalError() } + +@available(*, unavailable, message:"Use draw(_:in:byTiling:)") +public func CGContextDrawTiledImage(_ c: CGContext?, _ rect: CGRect, _ image: CGImage?) + { fatalError() } + +@available(*, unavailable, renamed:"getter:CGContext.textPosition(self:)") +public func CGContextGetTextPosition(_ c: CGContext?) -> CGPoint + { fatalError() } + +@available(*, unavailable, message:"Use var textPosition") +public func CGContextSetTextPosition(_ c: CGContext?, _ x: CGFloat, _ y: CGFloat) + { fatalError() } + +@available(*, unavailable, message:"Use showGlyphs(_:at:)") +public func CGContextShowGlyphsAtPositions(_ c: CGContext?, _ glyphs: UnsafePointer, _ Lpositions: UnsafePointer, _ count: Int) + { fatalError() } + +@available(*, unavailable, renamed:"CGContext.fillPath(self:)") +public func CGContextFillPath(_ c: CGContext?) + { fatalError() } + +@available(*, unavailable, message:"Use fillPath(using:)") +public func CGContextEOFillPath(_ c: CGContext?) + { fatalError() } + +@available(*, unavailable, renamed:"CGContext.clip(self:)") +public func CGContextClip(_ c: CGContext?) + { fatalError() } + +@available(*, unavailable, message:"Use clip(using:)") +public func CGContextEOClip(_ c: CGContext?) + { fatalError() } + +@available(*, unavailable, renamed:"CGGetLastMouseDelta") // different type +public func CGGetLastMouseDelta(_ deltaX: UnsafeMutablePointer?, _ deltaY: UnsafeMutablePointer?) + { fatalError() } + +@available(*, unavailable, message:"Use divided(atDistance:from:)") +public func CGRectDivide(_ rect: CGRect, _ slice: UnsafeMutablePointer, _ remainder: UnsafeMutablePointer, _ amount: CGFloat, _ edge: CGRectEdge) + { fatalError() } + +@available(*, unavailable, message:"Use CGPoint.init(dictionaryRepresentation:)") +public func CGPointMakeWithDictionaryRepresentation(_ dict: CFDictionary?, _ point: UnsafeMutablePointer) -> Bool + { fatalError() } + +@available(*, unavailable, message:"Use CGSize.init(dictionaryRepresentation:)") +public func CGSizeMakeWithDictionaryRepresentation(_ dict: CFDictionary?, _ size: UnsafeMutablePointer) -> Bool + { fatalError() } + +@available(*, unavailable, message:"Use CGRect.init(dictionaryRepresentation:)") +public func CGRectMakeWithDictionaryRepresentation(_ dict: CFDictionary?, _ rect: UnsafeMutablePointer) -> Bool + { fatalError() } + +@available(*, unavailable, renamed:"CGImage.copy(self:maskingColorComponents:)") +public func CGImageCreateWithMaskingColors(_ image: CGImage?, _ components: UnsafePointer) -> CGImage? + { fatalError() } + +@available(*, unavailable, message:"Use draw(_:in:)") +public func CGContextDrawLayerInRect(_ context: CGContext?, _ rect: CGRect, _ layer: CGLayer?) + { fatalError() } + +@available(*, unavailable, message:"Use draw(_:at:)") +public func CGContextDrawLayerAtPoint(_ context: CGContext?, _ point: CGPoint, _ layer: CGLayer?) + { fatalError() } + +@available(*, unavailable, message:"Use copy(byDashingWithPhase:lengths:transform:)") +public func CGPathCreateCopyByDashingPath(_ path: CGPath?, _ transform: UnsafePointer, _ phase: CGFloat, _ lengths: UnsafePointer, _ count: Int) -> CGPath? + { fatalError() } + +@available(*, unavailable, message:"Use copy(byStroking:lineWidth:lineCap:lineJoin:miterLimit:transform:)") +public func CGPathCreateCopyByStrokingPath(_ path: CGPath?, _ transform: UnsafePointer, _ lineWidth: CGFloat, _ lineCap: CGLineCap, _ lineJoin: CGLineJoin, _ miterLimit: CGFloat) -> CGPath? + { fatalError() } + +@available(*, unavailable, message:"Use == instead") +public func CGPathEqualToPath(_ path1: CGPath?, _ path2: CGPath?) -> Bool + { fatalError() } + +@available(*, unavailable, message:"Use move(to:transform:)") +public func CGPathMoveToPoint(_ path: CGMutablePath?, _ m: UnsafePointer, _ x: CGFloat, _ y: CGFloat) + { fatalError() } + +@available(*, unavailable, message:"Use addLine(to:transform:)") +public func CGPathAddLineToPoint(_ path: CGMutablePath?, _ m: UnsafePointer, _ x: CGFloat, _ y: CGFloat) + { fatalError() } + +@available(*, unavailable, message:"Use addCurve(to:control1:control2:transform:)") +public func CGPathAddCurveToPoint(_ path: CGMutablePath?, _ m: UnsafePointer, _ cp1x: CGFloat, _ cp1y: CGFloat, _ cp2x: CGFloat, _ cp2y: CGFloat, _ x: CGFloat, _ y: CGFloat) + { fatalError() } + +@available(*, unavailable, message:"Use addQuadCurve(to:control:transform:)") +public func CGPathAddQuadCurveToPoint(_ path: CGMutablePath?, _ m: UnsafePointer, _ cpx: CGFloat, _ cpy: CGFloat, _ x: CGFloat, _ y: CGFloat) + { fatalError() } + +@available(*, unavailable, message:"Use addRect(_:transform:)") +public func CGPathAddRect(_ path: CGMutablePath?, _ m: UnsafePointer, _ rect: CGRect) + { fatalError() } + +@available(*, unavailable, message:"Use addRects(_:transform:)") +public func CGPathAddRects(_ path: CGMutablePath?, _ m: UnsafePointer, _ rects: UnsafePointer, _ count: Int) + { fatalError() } + +@available(*, unavailable, message:"Use addLines(between:transform:)") +public func CGPathAddLines(_ path: CGMutablePath?, _ m: UnsafePointer, _ points: UnsafePointer, _ count: Int) + { fatalError() } + +@available(*, unavailable, message:"Use addEllipse(rect:transform:)") +public func CGPathAddEllipseInRect(_ path: CGMutablePath?, _ m: UnsafePointer, _ rect: CGRect) + { fatalError() } + +@available(*, unavailable, message:"Use addRelativeArc(center:radius:startAngle:delta:transform:)") +public func CGPathAddRelativeArc(_ path: CGMutablePath?, _ matrix: UnsafePointer, _ x: CGFloat, _ y: CGFloat, _ radius: CGFloat, _ startAngle: CGFloat, _ delta: CGFloat) + { fatalError() } + +@available(*, unavailable, message:"Use addArc(center:radius:startAngle:endAngle:clockwise:transform:)") +public func CGPathAddArc(_ path: CGMutablePath?, _ m: UnsafePointer, _ x: CGFloat, _ y: CGFloat, _ radius: CGFloat, _ startAngle: CGFloat, _ endAngle: CGFloat, _ clockwise: Bool) + { fatalError() } + +@available(*, unavailable, message:"Use addArc(tangent1End:tangent2End:radius:transform:)") +public func CGPathAddArcToPoint(_ path: CGMutablePath?, _ m: UnsafePointer, _ x1: CGFloat, _ y1: CGFloat, _ x2: CGFloat, _ y2: CGFloat, _ radius: CGFloat) + { fatalError() } + +@available(*, unavailable, message:"Use addPath(_:transform:)") +public func CGPathAddPath(_ path1: CGMutablePath?, _ m: UnsafePointer, _ path2: CGPath?) + { fatalError() } + +@available(*, unavailable, message:"Use CGColor.white") // retyped +public var kCGColorWhite: CFString + { fatalError() } + +@available(*, unavailable, message:"Use CGColor.black") // retyped +public var kCGColorBlack: CFString + { fatalError() } + +@available(*, unavailable, message:"Use CGColor.clear") // retyped +public var kCGColorClear: CFString + { fatalError() } + +// TODO: also add migration support from previous Swift3 betas? diff --git a/stdlib/public/SDK/Dispatch/Dispatch.swift b/stdlib/public/SDK/Dispatch/Dispatch.swift index ca16e03f0eb06..be49a3ab6ed7a 100644 --- a/stdlib/public/SDK/Dispatch/Dispatch.swift +++ b/stdlib/public/SDK/Dispatch/Dispatch.swift @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// @_exported import Dispatch +import SwiftShims /// dispatch_assert @@ -132,15 +133,15 @@ public extension DispatchGroup { public func notify(qos: DispatchQoS = .unspecified, flags: DispatchWorkItemFlags = [], queue: DispatchQueue, execute work: @escaping @convention(block) () -> ()) { if #available(OSX 10.10, iOS 8.0, *), qos != .unspecified || !flags.isEmpty { let item = DispatchWorkItem(qos: qos, flags: flags, block: work) - __dispatch_group_notify(self, queue, item._block) + _swift_dispatch_group_notify(self, queue, item._block) } else { - __dispatch_group_notify(self, queue, work) + _swift_dispatch_group_notify(self, queue, work) } } @available(OSX 10.10, iOS 8.0, *) public func notify(queue: DispatchQueue, work: DispatchWorkItem) { - __dispatch_group_notify(self, queue, work._block) + _swift_dispatch_group_notify(self, queue, work._block) } public func wait() { diff --git a/stdlib/public/SDK/Dispatch/Queue.swift b/stdlib/public/SDK/Dispatch/Queue.swift index 92bfd813a7275..111b2c9ed1613 100644 --- a/stdlib/public/SDK/Dispatch/Queue.swift +++ b/stdlib/public/SDK/Dispatch/Queue.swift @@ -197,10 +197,15 @@ public extension DispatchQueue { flags: DispatchWorkItemFlags = [], execute work: @escaping @convention(block) () -> Void) { - if group == nil && qos == .unspecified && flags.isEmpty { + if group == nil && qos == .unspecified { // Fast-path route for the most common API usage - __dispatch_async(self, work) - return + if flags.isEmpty { + _swift_dispatch_async(self, work) + return + } else if flags == .barrier { + _swift_dispatch_barrier_async(self, work) + return + } } var block: @convention(block) () -> Void = work @@ -210,9 +215,9 @@ public extension DispatchQueue { } if let g = group { - __dispatch_group_async(g, self, block) + _swift_dispatch_group_async(g, self, block) } else { - __dispatch_async(self, block) + _swift_dispatch_async(self, block) } } @@ -287,9 +292,9 @@ public extension DispatchQueue { { if #available(OSX 10.10, iOS 8.0, *), qos != .unspecified || !flags.isEmpty { let item = DispatchWorkItem(qos: qos, flags: flags, block: work) - __dispatch_after(deadline.rawValue, self, item._block) + _swift_dispatch_after(deadline.rawValue, self, item._block) } else { - __dispatch_after(deadline.rawValue, self, work) + _swift_dispatch_after(deadline.rawValue, self, work) } } @@ -301,20 +306,20 @@ public extension DispatchQueue { { if #available(OSX 10.10, iOS 8.0, *), qos != .unspecified || !flags.isEmpty { let item = DispatchWorkItem(qos: qos, flags: flags, block: work) - __dispatch_after(wallDeadline.rawValue, self, item._block) + _swift_dispatch_after(wallDeadline.rawValue, self, item._block) } else { - __dispatch_after(wallDeadline.rawValue, self, work) + _swift_dispatch_after(wallDeadline.rawValue, self, work) } } @available(OSX 10.10, iOS 8.0, *) public func asyncAfter(deadline: DispatchTime, execute: DispatchWorkItem) { - __dispatch_after(deadline.rawValue, self, execute._block) + _swift_dispatch_after(deadline.rawValue, self, execute._block) } @available(OSX 10.10, iOS 8.0, *) public func asyncAfter(wallDeadline: DispatchWallTime, execute: DispatchWorkItem) { - __dispatch_after(wallDeadline.rawValue, self, execute._block) + _swift_dispatch_after(wallDeadline.rawValue, self, execute._block) } @available(OSX 10.10, iOS 8.0, *) diff --git a/stdlib/public/SDK/Dispatch/Source.swift b/stdlib/public/SDK/Dispatch/Source.swift index f5b42c1dfcc2c..1d4d0e6b9b110 100644 --- a/stdlib/public/SDK/Dispatch/Source.swift +++ b/stdlib/public/SDK/Dispatch/Source.swift @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// // import Foundation +import SwiftShims public extension DispatchSourceProtocol { typealias DispatchSourceHandler = @convention(block) () -> Void @@ -20,15 +21,15 @@ public extension DispatchSourceProtocol { let h = handler, qos != .unspecified || !flags.isEmpty { let item = DispatchWorkItem(qos: qos, flags: flags, block: h) - __dispatch_source_set_event_handler(self as! DispatchSource, item._block) + _swift_dispatch_source_set_event_handler(self as! DispatchSource, item._block) } else { - __dispatch_source_set_event_handler(self as! DispatchSource, handler) + _swift_dispatch_source_set_event_handler(self as! DispatchSource, handler) } } @available(OSX 10.10, iOS 8.0, *) public func setEventHandler(handler: DispatchWorkItem) { - __dispatch_source_set_event_handler(self as! DispatchSource, handler._block) + _swift_dispatch_source_set_event_handler(self as! DispatchSource, handler._block) } public func setCancelHandler(qos: DispatchQoS = .unspecified, flags: DispatchWorkItemFlags = [], handler: DispatchSourceHandler?) { @@ -36,15 +37,15 @@ public extension DispatchSourceProtocol { let h = handler, qos != .unspecified || !flags.isEmpty { let item = DispatchWorkItem(qos: qos, flags: flags, block: h) - __dispatch_source_set_cancel_handler(self as! DispatchSource, item._block) + _swift_dispatch_source_set_cancel_handler(self as! DispatchSource, item._block) } else { - __dispatch_source_set_cancel_handler(self as! DispatchSource, handler) + _swift_dispatch_source_set_cancel_handler(self as! DispatchSource, handler) } } @available(OSX 10.10, iOS 8.0, *) public func setCancelHandler(handler: DispatchWorkItem) { - __dispatch_source_set_cancel_handler(self as! DispatchSource, handler._block) + _swift_dispatch_source_set_cancel_handler(self as! DispatchSource, handler._block) } public func setRegistrationHandler(qos: DispatchQoS = .unspecified, flags: DispatchWorkItemFlags = [], handler: DispatchSourceHandler?) { @@ -52,15 +53,15 @@ public extension DispatchSourceProtocol { let h = handler, qos != .unspecified || !flags.isEmpty { let item = DispatchWorkItem(qos: qos, flags: flags, block: h) - __dispatch_source_set_registration_handler(self as! DispatchSource, item._block) + _swift_dispatch_source_set_registration_handler(self as! DispatchSource, item._block) } else { - __dispatch_source_set_registration_handler(self as! DispatchSource, handler) + _swift_dispatch_source_set_registration_handler(self as! DispatchSource, handler) } } @available(OSX 10.10, iOS 8.0, *) public func setRegistrationHandler(handler: DispatchWorkItem) { - __dispatch_source_set_registration_handler(self as! DispatchSource, handler._block) + _swift_dispatch_source_set_registration_handler(self as! DispatchSource, handler._block) } @available(OSX 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *) diff --git a/stdlib/public/SDK/Dispatch/Time.swift b/stdlib/public/SDK/Dispatch/Time.swift index 08b2e1dff29ff..c6fd23c8c40e8 100644 --- a/stdlib/public/SDK/Dispatch/Time.swift +++ b/stdlib/public/SDK/Dispatch/Time.swift @@ -10,6 +10,8 @@ // //===----------------------------------------------------------------------===// +import SwiftShims + public struct DispatchTime : Comparable { public let rawValue: dispatch_time_t diff --git a/stdlib/public/SDK/Foundation/CMakeLists.txt b/stdlib/public/SDK/Foundation/CMakeLists.txt index ad9712b4e79ed..f9d1472e8835b 100644 --- a/stdlib/public/SDK/Foundation/CMakeLists.txt +++ b/stdlib/public/SDK/Foundation/CMakeLists.txt @@ -37,7 +37,7 @@ add_swift_library(swiftFoundation ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SD Hashing.m Thunks.mm - SWIFT_MODULE_DEPENDS ObjectiveC CoreGraphics Dispatch + SWIFT_MODULE_DEPENDS ObjectiveC CoreGraphics Dispatch os SWIFT_MODULE_DEPENDS_OSX XPC FRAMEWORK_DEPENDS Foundation) diff --git a/stdlib/public/SDK/Foundation/Foundation.swift b/stdlib/public/SDK/Foundation/Foundation.swift index e59c8c8539f04..458ae79e9101a 100644 --- a/stdlib/public/SDK/Foundation/Foundation.swift +++ b/stdlib/public/SDK/Foundation/Foundation.swift @@ -1242,8 +1242,28 @@ extension NSSet { /// receiver. @nonobjc public convenience init(set anSet: NSSet) { - // FIXME: This is a bit weird. Maybe there's a better way? - self.init(set: anSet as Set as Set) + // FIXME(performance)(compiler limitation): we actually want to do just + // `self = anSet.copy()`, but Swift does not have factory + // initializers right now. + let numElems = anSet.count + let stride = MemoryLayout>.stride + let alignment = MemoryLayout>.alignment + let bufferSize = stride * numElems + assert(stride == MemoryLayout.stride) + assert(alignment == MemoryLayout.alignment) + + let rawBuffer = UnsafeMutableRawPointer.allocate( + bytes: bufferSize, alignedTo: alignment) + defer { + rawBuffer.deallocate(bytes: bufferSize, alignedTo: alignment) + _fixLifetime(anSet) + } + let valueBuffer = rawBuffer.bindMemory( + to: Optional.self, capacity: numElems) + + CFSetGetValues(anSet, valueBuffer) + let valueBufferForInit = rawBuffer.assumingMemoryBound(to: AnyObject.self) + self.init(objects: valueBufferForInit, count: numElems) } } @@ -1256,12 +1276,47 @@ extension NSDictionary { /// found in `otherDictionary`. @objc(_swiftInitWithDictionary_NSDictionary:) public convenience init(dictionary otherDictionary: NSDictionary) { - // FIXME: This is a bit weird. Maybe there's a better way? - self.init(dictionary: otherDictionary as [NSObject: AnyObject] - as [AnyHashable: Any]) + // FIXME(performance)(compiler limitation): we actually want to do just + // `self = otherDictionary.copy()`, but Swift does not have factory + // initializers right now. + let numElems = otherDictionary.count + let stride = MemoryLayout.stride + let alignment = MemoryLayout.alignment + let singleSize = stride * numElems + let totalSize = singleSize * 2 + _sanityCheck(stride == MemoryLayout.stride) + _sanityCheck(alignment == MemoryLayout.alignment) + + // Allocate a buffer containing both the keys and values. + let buffer = UnsafeMutableRawPointer.allocate( + bytes: totalSize, alignedTo: alignment) + defer { + buffer.deallocate(bytes: totalSize, alignedTo: alignment) + _fixLifetime(otherDictionary) + } + + let valueBuffer = buffer.bindMemory(to: AnyObject.self, capacity: numElems) + let buffer2 = buffer + singleSize + let keyBuffer = buffer2.bindMemory(to: AnyObject.self, capacity: numElems) + + _stdlib_NSDictionary_getObjects( + nsDictionary: otherDictionary, + objects: valueBuffer, + andKeys: keyBuffer) + + let keyBufferCopying = buffer2.assumingMemoryBound(to: NSCopying.self) + self.init(objects: valueBuffer, forKeys: keyBufferCopying, count: numElems) } } +@_silgen_name("__NSDictionaryGetObjects") +func _stdlib_NSDictionary_getObjects( + nsDictionary: NSDictionary, + objects: UnsafeMutablePointer?, + andKeys keys: UnsafeMutablePointer? +) + + //===----------------------------------------------------------------------===// // NSUndoManager //===----------------------------------------------------------------------===// diff --git a/stdlib/public/SDK/Foundation/NSError.swift b/stdlib/public/SDK/Foundation/NSError.swift index 9125e49ecbfec..fa164664be82f 100644 --- a/stdlib/public/SDK/Foundation/NSError.swift +++ b/stdlib/public/SDK/Foundation/NSError.swift @@ -241,6 +241,11 @@ extension NSError : Error { public var _domain: String { return domain } public var _code: Int { return code } public var _userInfo: Any? { return userInfo } + + /// The "embedded" NSError is itself. + public func _getEmbeddedNSError() -> AnyObject? { + return self + } } extension CFError : Error { @@ -255,6 +260,11 @@ extension CFError : Error { public var _userInfo: Any? { return CFErrorCopyUserInfo(self) as Any } + + /// The "embedded" NSError is itself. + public func _getEmbeddedNSError() -> AnyObject? { + return self + } } // An error value to use when an Objective-C API indicates error @@ -496,6 +506,11 @@ extension _ErrorCodeProtocol where Self._ErrorType: _BridgedStoredNSError { } extension _BridgedStoredNSError { + /// Retrieve the embedded NSError from a bridged, stored NSError. + public func _getEmbeddedNSError() -> AnyObject? { + return _nsError + } + public static func == (lhs: Self, rhs: Self) -> Bool { return lhs._nsError.isEqual(rhs._nsError) } diff --git a/stdlib/public/SDK/Foundation/Thunks.mm b/stdlib/public/SDK/Foundation/Thunks.mm index e9ee7ab267c40..9b3b2f80ac1aa 100644 --- a/stdlib/public/SDK/Foundation/Thunks.mm +++ b/stdlib/public/SDK/Foundation/Thunks.mm @@ -212,3 +212,13 @@ void *_Nullable contextInfo) { objc_msgSend(delegate, selector, success, contextInfo); } + +// -- NSDictionary +SWIFT_CC(swift) +extern "C" void +__NSDictionaryGetObjects(NSDictionary *_Nonnull nsDictionary, + id *objects, id *keys) { + [nsDictionary getObjects:objects andKeys:keys]; + [nsDictionary release]; +} + diff --git a/stdlib/public/SDK/GameplayKit/GameplayKit.mm b/stdlib/public/SDK/GameplayKit/GameplayKit.mm index 47833b4d3fd30..f68498880adc2 100644 --- a/stdlib/public/SDK/GameplayKit/GameplayKit.mm +++ b/stdlib/public/SDK/GameplayKit/GameplayKit.mm @@ -14,15 +14,6 @@ #include "swift/Runtime/Config.h" -extern "C" SWIFT_CC(swift) NS_RETURNS_RETAINED GKComponent * _Nullable -GK_Swift_GKEntity_componentForClass(id NS_RELEASES_ARGUMENT __nonnull self_, - Class __nonnull componentClass) { - GKEntity *entity = self_; - id component = [[entity componentForClass:componentClass] retain]; - [self_ release]; - return component; -} - extern "C" SWIFT_CC(swift) NS_RETURNS_RETAINED GKState * _Nullable GK_Swift_GKStateMachine_stateForClass(id NS_RELEASES_ARGUMENT __nonnull self_, Class __nonnull stateClass) { diff --git a/stdlib/public/SDK/GameplayKit/GameplayKit.swift b/stdlib/public/SDK/GameplayKit/GameplayKit.swift index c68a08b9df0c9..6d57c22e85e44 100644 --- a/stdlib/public/SDK/GameplayKit/GameplayKit.swift +++ b/stdlib/public/SDK/GameplayKit/GameplayKit.swift @@ -10,23 +10,65 @@ // //===----------------------------------------------------------------------===// -@_exported import GameplayKit +@_exported import GameplayKit // Clang module +import CoreGraphics +import simd -@_silgen_name("GK_Swift_GKEntity_componentForClass") -internal func GK_Swift_GKEntity_componentForClass( - _ self_: AnyObject, - _ componentClass: AnyObject) -> AnyObject? + +@available(iOS, introduced: 9.0) +@available(OSX, introduced: 10.11) +@available(tvOS, introduced: 9.0) +extension GKPath { + /// Creates a path from an array of points + /// - Parameter points: an array of simd.float2 points to make a path from + /// - Parameter radius: radius of the path to create + /// - Parameter cyclical: if the path is of a cycle that loops back on itself + public convenience init(points: [simd.float2], radius: Float, cyclical: Bool) { + var variablePoints = points + self.init(__points: &variablePoints, count: points.count, radius: radius, cyclical: cyclical) + } +} + + +@available(iOS, introduced: 10.0) +@available(OSX, introduced: 10.12) +@available(tvOS, introduced: 10.0) +extension GKPath { + /// Creates a path from an array of points + /// - Parameter points: an array of simd.float3 points to make a path from + /// - Parameter radius: the radius of the path to create + /// - Parameter cyclical: if the path is of a cycle that loops back on itself + public convenience init(points: [simd.float3], radius: Float, cyclical: Bool) { + var variablePoints = points + self.init(__float3Points: &variablePoints, count: points.count, radius: radius, cyclical: cyclical) + } +} + +@available(iOS, introduced: 9.0) +@available(OSX, introduced: 10.11) +@available(tvOS, introduced: 9.0) +extension GKPolygonObstacle { + /// Creates a polygon obstacle with an array of points. + /// - Parameter points: array of points in counter-clockwise order that are the vertices of a convex polygon + public convenience init(points: [simd.float2]) { + var variablePoints = points + self.init(__points: &variablePoints, count: points.count) + } +} @available(iOS, introduced: 9.0) @available(OSX, introduced: 10.11) @available(tvOS, introduced: 9.0) extension GKEntity { - /// Returns the component instance of the indicated class contained by the - /// entity. Returns nil if entity does not have this component. - public func componentForClass( - _ componentClass: ComponentType.Type) -> ComponentType? { - return GK_Swift_GKEntity_componentForClass( - self, componentClass) as! ComponentType? + /// Gets the component of the indicated class. Returns nil if entity does not have this component + /// - Parameter ofType: the type of the component you want to get + public func component(ofType componentClass: ComponentType.Type) -> ComponentType? { + return self.__component(for: componentClass) as? ComponentType + } + /// Removes the component of the indicates class from this entity + /// - Parameter ofType: the type of component you want to remove + public func removeComponent(ofType componentClass: ComponentType.Type) { + self.__removeComponent(for: componentClass) } } @@ -39,11 +81,12 @@ internal func GK_Swift_GKStateMachine_stateForClass( @available(OSX, introduced: 10.11) @available(tvOS, introduced: 9.0) extension GKStateMachine { - /// Returns the state instance of the indicated class contained by the state - /// machine. Returns nil if state machine does not have this state. - public func stateForClass( - _ stateClass: StateType.Type) -> StateType? { + /// Gets the state of the indicated class. Returns nil if the state machine does not have this state. + /// - Parameter forClass: the type of the state you want to get + public func state( + forClass stateClass: StateType.Type) -> StateType? { return GK_Swift_GKStateMachine_stateForClass( self, stateClass) as! StateType? } } + diff --git a/stdlib/public/SDK/Intents/CMakeLists.txt b/stdlib/public/SDK/Intents/CMakeLists.txt index 9908a78cb918e..4f81907280eb2 100644 --- a/stdlib/public/SDK/Intents/CMakeLists.txt +++ b/stdlib/public/SDK/Intents/CMakeLists.txt @@ -3,7 +3,6 @@ add_swift_library(swiftIntents ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_O INBooleanResolutionResult.swift INDoubleResolutionResult.swift INIntegerResolutionResult.swift - INListRideOptionsIntentResponse.swift INRequestRideIntent.swift INSaveProfileInCarIntent.swift INSearchForPhotosIntentResponse.swift @@ -14,7 +13,6 @@ add_swift_library(swiftIntents ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_O INSetSeatSettingsInCarIntent.swift INStartPhotoPlaybackIntentResponse.swift INStartWorkoutIntent.swift - INTemperature.swift TARGET_SDKS OSX IOS IOS_SIMULATOR SWIFT_MODULE_DEPENDS Foundation CoreLocation diff --git a/stdlib/public/SDK/Intents/INListRideOptionsIntentResponse.swift b/stdlib/public/SDK/Intents/INListRideOptionsIntentResponse.swift deleted file mode 100644 index c5cc4340397b8..0000000000000 --- a/stdlib/public/SDK/Intents/INListRideOptionsIntentResponse.swift +++ /dev/null @@ -1,29 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See http://swift.org/LICENSE.txt for license information -// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -@_exported import Intents -import Foundation - -#if os(iOS) -@available(iOS 10.0, *) -extension INListRideOptionsIntentResponse { - @nonobjc - public final var supportsApplePayForPayment: Bool? { - get { - return __supportsApplePayForPayment?.boolValue - } - set { - __supportsApplePayForPayment = newValue.map { NSNumber(value: $0) } - } - } -} -#endif diff --git a/stdlib/public/SDK/Intents/INRequestRideIntent.swift b/stdlib/public/SDK/Intents/INRequestRideIntent.swift index a96cc4406ad90..3207c47799895 100644 --- a/stdlib/public/SDK/Intents/INRequestRideIntent.swift +++ b/stdlib/public/SDK/Intents/INRequestRideIntent.swift @@ -22,26 +22,18 @@ extension INRequestRideIntent { dropOffLocation: CLPlacemark? = nil, rideOptionName: INSpeakableString? = nil, partySize: Int? = nil, - paymentMethodName: INSpeakableString? = nil, - usesApplePayForPayment: Bool? = nil + paymentMethod: INPaymentMethod? = nil ) { self.init(__pickupLocation: pickupLocation, dropOffLocation: dropOffLocation, rideOptionName: rideOptionName, partySize: partySize.map { NSNumber(value: $0) }, - paymentMethodName: paymentMethodName, - usesApplePayForPayment: - usesApplePayForPayment.map { NSNumber(value: $0) }) + paymentMethod: paymentMethod) } @nonobjc public final var partySize: Int? { return __partySize?.intValue } - - @nonobjc - public final var usesApplePayForPayment: Bool? { - return __usesApplePayForPayment?.boolValue - } } #endif diff --git a/stdlib/public/SDK/Intents/INSetClimateSettingsInCarIntent.swift b/stdlib/public/SDK/Intents/INSetClimateSettingsInCarIntent.swift index 23b5e126f292b..03c2e4e63cf96 100644 --- a/stdlib/public/SDK/Intents/INSetClimateSettingsInCarIntent.swift +++ b/stdlib/public/SDK/Intents/INSetClimateSettingsInCarIntent.swift @@ -26,7 +26,7 @@ extension INSetClimateSettingsInCarIntent { fanSpeedIndex: Int? = nil, fanSpeedPercentage: Int? = nil, relativeFanSpeedSetting: INRelativeSetting = .unknown, - temperature: INTemperature? = nil, + temperature: Measurement? = nil, relativeTemperatureSetting: INRelativeSetting = .unknown, climateZone: INCarSeat = .unknown) { self.init(__enableFan: enableFan.map { NSNumber(value: $0) }, diff --git a/stdlib/public/SDK/Intents/INTemperature.swift b/stdlib/public/SDK/Intents/INTemperature.swift deleted file mode 100644 index 68b9cb2f86387..0000000000000 --- a/stdlib/public/SDK/Intents/INTemperature.swift +++ /dev/null @@ -1,35 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See http://swift.org/LICENSE.txt for license information -// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -@_exported import Intents -import Foundation - -#if os(iOS) -@available(iOS 10.0, *) -extension INTemperature { - @nonobjc - public convenience init(value: Double, unit: UnitTemperature) { - self.init(__unit: unit, value: NSNumber(value: value)) - } - - @nonobjc - public convenience init(_ measurement: Measurement) { - self.init(__unit: measurement.unit, - value: NSNumber(value: measurement.value)) - } - - @nonobjc - public final var value: Double? { - return __value?.doubleValue - } -} -#endif diff --git a/stdlib/public/SDK/SpriteKit/SpriteKit.swift b/stdlib/public/SDK/SpriteKit/SpriteKit.swift index d03e5922e3db0..b29e33cb21a1d 100644 --- a/stdlib/public/SDK/SpriteKit/SpriteKit.swift +++ b/stdlib/public/SDK/SpriteKit/SpriteKit.swift @@ -1,10 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See http://swift.org/LICENSE.txt for license information +// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + @_exported import SpriteKit +import simd // SpriteKit defines SKColor using a macro. #if os(OSX) public typealias SKColor = NSColor -#elseif os(iOS) || os(tvOS) +#elseif os(iOS) || os(tvOS) || os(watchOS) public typealias SKColor = UIColor #endif @@ -15,3 +28,58 @@ public typealias SKColor = UIColor override init() { _sanityCheckFailure("don't touch me") } @objc func _copyImageData() -> NSData! { return nil } } + +@available(iOS, introduced: 10.0) +@available(OSX, introduced: 10.12) +@available(tvOS, introduced: 10.0) +@available(watchOS, introduced: 3.0) +extension SKWarpGeometryGrid { + /// Create a grid of the specified dimensions, source and destination positions. + /// + /// Grid dimensions (columns and rows) refer to the number of faces in each dimension. The + /// number of vertices required for a given dimension is equal to (cols + 1) * (rows + 1). + /// + /// SourcePositions are normalized (0.0 - 1.0) coordinates to determine the source content. + /// + /// DestinationPositions are normalized (0.0 - 1.0) positional coordinates with respect to + /// the node's native size. Values outside the (0.0-1.0) range are perfectly valid and + /// correspond to positions outside of the native undistorted bounds. + /// + /// Source and destination positions are provided in row-major order staring from the top-left. + /// For example the indices for a 2x2 grid would be as follows: + /// + /// [0]---[1]---[2] + /// | | | + /// [3]---[4]---[5] + /// | | | + /// [6]---[7]---[8] + /// + /// - Parameter columns: the number of columns to initialize the SKWarpGeometryGrid with + /// - Parameter rows: the number of rows to initialize the SKWarpGeometryGrid with + /// - Parameter sourcePositions: the source positions for the SKWarpGeometryGrid to warp from + /// - Parameter destinationPositions: the destination positions for SKWarpGeometryGrid to warp to + public convenience init(columns: Int, rows: Int, sourcePositions: [simd.float2] = [float2](), destinationPositions: [simd.float2] = [float2]()) { + let requiredElementsCount = (columns + 1) * (rows + 1) + switch (destinationPositions.count, sourcePositions.count) { + case (0, 0): + self.init(__columns: columns, rows: rows, sourcePositions: nil, destPositions: nil) + case (let dests, 0): + _precondition(dests == requiredElementsCount, "Mismatch found between rows/columns and positions.") + self.init(__columns: columns, rows: rows, sourcePositions: nil, destPositions: destinationPositions) + case (0, let sources): + _precondition(sources == requiredElementsCount, "Mismatch found between rows/columns and positions.") + self.init(__columns: columns, rows: rows, sourcePositions: sourcePositions, destPositions: nil) + case (let dests, let sources): + _precondition(dests == requiredElementsCount && sources == requiredElementsCount, "Mismatch found between rows/columns and positions.") + self.init(__columns: columns, rows: rows, sourcePositions: sourcePositions, destPositions: destinationPositions) + } + } + + public func replacingBySourcePositions(positions source: [simd.float2]) -> SKWarpGeometryGrid { + return self.__replacingSourcePositions(source) + } + + public func replacingByDestinationPositions(positions destination: [simd.float2]) -> SKWarpGeometryGrid { + return self.__replacingDestPositions(destination) + } +} diff --git a/stdlib/public/SDK/XCTest/CMakeLists.txt b/stdlib/public/SDK/XCTest/CMakeLists.txt index 5862301164750..3322c88f82e5a 100644 --- a/stdlib/public/SDK/XCTest/CMakeLists.txt +++ b/stdlib/public/SDK/XCTest/CMakeLists.txt @@ -7,7 +7,7 @@ add_swift_library(swiftXCTest ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OV SWIFT_MODULE_DEPENDS ObjectiveC Foundation FRAMEWORK_DEPENDS Foundation XCTest SWIFT_MODULE_DEPENDS_OSX AppKit - SWIFT_MODULE_DEPENDS_IOS UIKit + SWIFT_MODULE_DEPENDS_IOS CoreMedia UIKit SWIFT_MODULE_DEPENDS_TVOS UIKit DONT_EMBED_BITCODE) diff --git a/stdlib/public/SDK/os/CMakeLists.txt b/stdlib/public/SDK/os/CMakeLists.txt new file mode 100644 index 0000000000000..1b5ae9b6d1f5f --- /dev/null +++ b/stdlib/public/SDK/os/CMakeLists.txt @@ -0,0 +1,5 @@ +add_swift_library(swiftos ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY + os.swift + os.mm + SWIFT_MODULE_DEPENDS ObjectiveC Dispatch + SWIFT_MODULE_DEPENDS_OSX XPC) diff --git a/stdlib/public/SDK/os/os.mm b/stdlib/public/SDK/os/os.mm new file mode 100644 index 0000000000000..1707a465c30b5 --- /dev/null +++ b/stdlib/public/SDK/os/os.mm @@ -0,0 +1,422 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See http://swift.org/LICENSE.txt for license information +// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef os_fastpath +#define os_fastpath(x) ((__typeof__(x))OS_EXPECT((long)(x), ~0l)) +#endif +#ifndef os_slowpath +#define os_slowpath(x) ((__typeof__(x))OS_EXPECT((long)(x), 0l)) +#endif +#ifndef os_likely +#define os_likely(x) OS_EXPECT(!!(x), 1) +#endif +#ifndef os_unlikely +#define os_unlikely(x) OS_EXPECT(!!(x), 0) +#endif + +#ifndef MIN +#define MIN(a, b) (((a)<(b))?(a):(b)) +#endif + +#define OST_FORMAT_MAX_STRING_SIZE 1024 + +#define OS_LOG_PRIVACY_OPTION_DEFAULT 0 +#define OS_LOG_PRIVACY_OPTION_PRIVATE 1 +#define OS_LOG_PRIVACY_OPTION_PUBLIC 2 + +enum os_trace_int_types_t { + T_CHAR = -2, + T_SHORT = -1, + T_INT = 0, + T_LONG = 1, + T_LONGLONG = 2, + T_SIZE = 3, + T_INTMAX = 4, + T_PTRDIFF = 5, +}; + +OS_ENUM(os_log_value_type, uint8_t, + OS_LOG_BUFFER_VALUE_TYPE_SCALAR = 0, + OS_LOG_BUFFER_VALUE_TYPE_COUNT = 1, + OS_LOG_BUFFER_VALUE_TYPE_STRING = 2, + OS_LOG_BUFFER_VALUE_TYPE_POINTER = 3, + OS_LOG_BUFFER_VALUE_TYPE_OBJECT = 4, +); + +OS_ENUM(os_log_value_subtype, uint8_t, + OS_LOG_BUFFER_VALUE_SUBTYPE_NONE = 0, + OS_LOG_BUFFER_VALUE_SUBTYPE_INTEGER = 1, + OS_LOG_BUFFER_VALUE_SUBTYPE_FLOAT = 2, +); + +enum os_log_int_types_t { + OST_CHAR = -2, + OST_SHORT = -1, + OST_INT = 0, + OST_LONG = 1, + OST_LONGLONG = 2, + OST_SIZE = 3, + OST_INTMAX = 4, + OST_PTRDIFF = 5, +}; + +union os_log_format_types_u { + uint16_t u16; + uint32_t u32; + uint64_t u64; + char ch; + short s; + int i; + void *p; + char *pch; + wchar_t wch; + wchar_t *pwch; + size_t z; + intmax_t im; + ptrdiff_t pd; + long l; + long long ll; + double d; + float f; + long double ld; +}; + +typedef struct os_log_format_value_s { + union os_log_format_types_u type; + os_log_value_type_t ctype; + uint16_t size; +} *os_log_format_value_t; + +typedef struct os_log_buffer_value_s { +#define OS_LOG_CONTENT_FLAG_PRIVATE 0x1 +#define OS_LOG_CONTENT_FLAG_PUBLIC 0x2 + uint8_t flags : 4; + os_log_value_type_t type : 4; + uint8_t size; + uint8_t value[]; +} *os_log_buffer_value_t; + +typedef struct os_log_buffer_s { +#define OS_LOG_BUFFER_HAS_PRIVATE 0x1 +#define OS_LOG_BUFFER_HAS_NON_SCALAR 0x2 +#define OS_LOG_BUFFER_MAX_SIZE 1024 + uint8_t flags; + uint8_t arg_cnt; + uint8_t content[]; +} *os_log_buffer_t; + +typedef struct os_log_buffer_context_s { + os_log_t log; + os_log_buffer_t buffer; + + // sizes and offsets + uint16_t content_off; // offset into buffer->content + uint16_t content_sz; // size not including the header + uint8_t arg_idx; +} *os_log_buffer_context_t; + +static bool +_os_log_encode_arg(const void *arg, uint16_t arg_len, os_log_value_type_t ctype, uint8_t flags, os_log_buffer_context_t context) +{ + os_log_buffer_value_t content = (os_log_buffer_value_t) &context->buffer->content[context->content_off]; + size_t content_sz = sizeof(*content) + arg_len; + + content->type = ctype; + content->flags = flags; + + switch (ctype) { + case OS_LOG_BUFFER_VALUE_TYPE_COUNT: + case OS_LOG_BUFFER_VALUE_TYPE_SCALAR: + if ((context->content_off + content_sz) > context->content_sz) { + return false; + } + + memcpy(content->value, arg, arg_len); + content->size = arg_len; + context->content_off += content_sz; + break; + + case OS_LOG_BUFFER_VALUE_TYPE_STRING: + case OS_LOG_BUFFER_VALUE_TYPE_POINTER: + case OS_LOG_BUFFER_VALUE_TYPE_OBJECT: + memcpy(content->value, arg, arg_len); + context->buffer->flags |= OS_LOG_BUFFER_HAS_NON_SCALAR; + content->size = arg_len; + context->content_off += content_sz; + break; + + } + + if (content->flags & OS_LOG_CONTENT_FLAG_PRIVATE) { + context->buffer->flags |= OS_LOG_BUFFER_HAS_PRIVATE; + } + + context->arg_idx++; + + return true; +} + +static bool +_os_log_encode(const char *format, va_list args, int saved_errno, os_log_buffer_context_t context) +{ + const char *percent = strchr(format, '%'); + + while (percent != NULL) { + ++percent; + if (percent[0] != '%') { + struct os_log_format_value_s value; + uint8_t flags = 0; + int type = T_INT; + bool long_double = false; + int prec = 0; + char ch; + + for (bool done = false; !done; percent++) { + switch (ch = percent[0]) { + /* type of types or other */ + case 'l': // longer + type++; + break; + + case 'h': // shorter + type--; + break; + + case 'z': + type = T_SIZE; + break; + + case 'j': + type = T_INTMAX; + break; + + case 't': + type = T_PTRDIFF; + break; + + case '.': // precision + if ((percent[1]) == '*') { + prec = va_arg(args, int); + _os_log_encode_arg(&prec, sizeof(prec), OS_LOG_BUFFER_VALUE_TYPE_COUNT, flags, context); + percent++; + continue; + } else { + // we have to read the precision and do the right thing + const char *fmt = percent + 1; + prec = 0; + while (isdigit(ch = *fmt++)) { + prec = 10 * prec + (ch - '0'); + } + + if (prec > 1024) { + prec = 1024; + } + + _os_log_encode_arg(&prec, sizeof(prec), OS_LOG_BUFFER_VALUE_TYPE_COUNT, flags, context); + } + break; + + case '-': // left-align + case '+': // force sign + case ' ': // prefix non-negative with space + case '#': // alternate + case '\'': // group by thousands + break; + + case '{': // annotated symbols + for (const char *curr2 = percent + 1; (ch = (*curr2)) != 0; curr2++) { + if (ch == '}') { + if (strncmp(percent + 1, "private", MIN(curr2 - percent - 1, 7)) == 0) { + flags |= OS_LOG_CONTENT_FLAG_PRIVATE; + } + percent = curr2; + break; + } + } + break; + + /* fixed types */ + case 'd': // integer + case 'i': // integer + case 'o': // octal + case 'u': // unsigned + case 'x': // hex + case 'X': // upper-hex + switch (type) { + case T_CHAR: + value.type.ch = va_arg(args, int); + _os_log_encode_arg(&value.type.ch, sizeof(value.type.ch), OS_LOG_BUFFER_VALUE_TYPE_SCALAR, flags, context); + break; + + case T_SHORT: + value.type.s = va_arg(args, int); + _os_log_encode_arg(&value.type.s, sizeof(value.type.s), OS_LOG_BUFFER_VALUE_TYPE_SCALAR, flags, context); + break; + + case T_INT: + value.type.i = va_arg(args, int); + _os_log_encode_arg(&value.type.i, sizeof(value.type.i), OS_LOG_BUFFER_VALUE_TYPE_SCALAR, flags, context); + break; + + case T_LONG: + value.type.l = va_arg(args, long); + _os_log_encode_arg(&value.type.l, sizeof(value.type.l), OS_LOG_BUFFER_VALUE_TYPE_SCALAR, flags, context); + break; + + case T_LONGLONG: + value.type.ll = va_arg(args, long long); + _os_log_encode_arg(&value.type.ll, sizeof(value.type.ll), OS_LOG_BUFFER_VALUE_TYPE_SCALAR, flags, context); + break; + + case T_SIZE: + value.type.z = va_arg(args, size_t); + _os_log_encode_arg(&value.type.z, sizeof(value.type.z), OS_LOG_BUFFER_VALUE_TYPE_SCALAR, flags, context); + break; + + case T_INTMAX: + value.type.im = va_arg(args, intmax_t); + _os_log_encode_arg(&value.type.im, sizeof(value.type.im), OS_LOG_BUFFER_VALUE_TYPE_SCALAR, flags, context); + break; + + case T_PTRDIFF: + value.type.pd = va_arg(args, ptrdiff_t); + _os_log_encode_arg(&value.type.pd, sizeof(value.type.pd), OS_LOG_BUFFER_VALUE_TYPE_SCALAR, flags, context); + break; + + default: + return false; + } + done = true; + break; + + case 'P': // pointer data + if (prec > 0) { // only encode a pointer if we have been given a length + context->buffer->flags |= OS_LOG_BUFFER_HAS_NON_SCALAR; + value.type.p = va_arg(args, void *); + + _os_log_encode_arg(value.type.p, prec, OS_LOG_BUFFER_VALUE_TYPE_POINTER, flags, context); + prec = 0; + done = true; + } + break; + + case 'L': // long double + long_double = true; + break; + + case 'a': case 'A': case 'e': case 'E': // floating types + case 'f': case 'F': case 'g': case 'G': + if (long_double) { + value.type.ld = va_arg(args, long double); + _os_log_encode_arg(&value.type.ld, sizeof(value.type.ld), OS_LOG_BUFFER_VALUE_TYPE_SCALAR, flags, context); + } else { + value.type.d = va_arg(args, double); + _os_log_encode_arg(&value.type.d, sizeof(value.type.d), OS_LOG_BUFFER_VALUE_TYPE_SCALAR, flags, context); + } + done = true; + break; + + case 'c': // char + value.type.ch = va_arg(args, int); + _os_log_encode_arg(&value.type.ch, sizeof(value.type.ch), OS_LOG_BUFFER_VALUE_TYPE_SCALAR, flags, context); + done = true; + break; + + case 'C': // wide-char + value.type.wch = va_arg(args, wint_t); + _os_log_encode_arg(&value.type.wch, sizeof(value.type.wch), OS_LOG_BUFFER_VALUE_TYPE_SCALAR, flags, context); + done = true; + break; + +#if 0 + // String types get sent from Swift as NSString objects. + case 's': // string + value.type.pch = va_arg(args, char *); + context->buffer->flags |= OS_LOG_BUFFER_HAS_NON_SCALAR; + _os_log_encode_arg(&value.type.pch, sizeof(value.type.pch), OS_LOG_BUFFER_VALUE_TYPE_STRING, flags, context); + prec = 0; + done = true; + break; +#endif + + case '@': // CFTypeRef aka NSObject * + value.type.p = va_arg(args, void *); + context->buffer->flags |= OS_LOG_BUFFER_HAS_NON_SCALAR; + _os_log_encode_arg(&value.type.p, sizeof(value.type.p), OS_LOG_BUFFER_VALUE_TYPE_OBJECT, flags, context); + done = true; + break; + + case 'm': + value.type.i = saved_errno; + _os_log_encode_arg(&value.type.i, sizeof(value.type.i), OS_LOG_BUFFER_VALUE_TYPE_SCALAR, flags, context); + done = true; + break; + + default: + if (isdigit(ch)) { // [0-9] + continue; + } + return false; + } + + if (done) { + percent = strchr(percent, '%'); // Find next format + break; + } + } + } else { + percent = strchr(percent+1, '%'); // Find next format after %% + } + } + + context->buffer->arg_cnt = context->arg_idx; + context->content_sz = context->content_off; + context->arg_idx = context->content_off = 0; + + return true; +} + +#include "swift/Runtime/Config.h" + +SWIFT_CC(swift) __attribute__((__visibility__("default"))) +extern "C" void +_swift_os_log(void *dso, os_log_t oslog, os_log_type_t type, const char *format, va_list args) +{ + struct os_log_buffer_context_s context = { 0, 0, 0, 0, 0 }; + os_log_buffer_t buffer = (os_log_buffer_t)alloca(OS_LOG_BUFFER_MAX_SIZE); + int save_errno = errno; // %m + + memset(buffer, 0, OS_LOG_BUFFER_MAX_SIZE); + + context.buffer = buffer; + context.content_sz = OS_LOG_BUFFER_MAX_SIZE - sizeof(*buffer); + + if (_os_log_encode(format, args, save_errno, &context)) { + _os_log_impl(dso, oslog, type, format, (uint8_t *)buffer, context.content_sz); + } +} + +SWIFT_CC(swift) __attribute__((__visibility__("default"))) +extern "C" os_log_t +_swift_os_log_default(void) { + return OS_LOG_DEFAULT; +} diff --git a/stdlib/public/SDK/os/os.swift b/stdlib/public/SDK/os/os.swift new file mode 100644 index 0000000000000..7ba4a5551d116 --- /dev/null +++ b/stdlib/public/SDK/os/os.swift @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See http://swift.org/LICENSE.txt for license information +// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +@_exported import os +@_exported import os.log + +@available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) +public func os_log( + _ message: StaticString, + dso: UnsafeRawPointer? = #dsohandle, + log: OSLog = .default, + type: OSLogType = .default, + _ args: CVarArg...) +{ + guard log.isEnabled(type: type) else { return } + + message.withUTF8Buffer { (buf: UnsafeBufferPointer) in + // Since dladdr is in libc, it is safe to unsafeBitCast + // the cstring argument type. + let str = unsafeBitCast(buf.baseAddress!, to: UnsafePointer.self) + let valist = getVaList(args) + _swift_os_log(dso, log, type, str, valist) + } +} + +extension OSLogType { + @available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) + public static let `default` = __OS_LOG_TYPE_DEFAULT + + @available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) + public static let info = __OS_LOG_TYPE_INFO + + @available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) + public static let debug = __OS_LOG_TYPE_DEBUG + + @available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) + public static let error = __OS_LOG_TYPE_ERROR + + @available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) + public static let fault = __OS_LOG_TYPE_FAULT +} + +extension OSLog { + @available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) + public static let `default` = _swift_os_log_default() + + @available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) + public convenience init(subsystem: String, category: String) { + self.init(__subsystem: subsystem, category: category) + } +} + +@_silgen_name("_swift_os_log") +internal func _swift_os_log(_ dso: UnsafeRawPointer!, _ log: OSLog, _ type: OSLogType, _ format: UnsafePointer!, _ args: CVaListPointer) + +@_silgen_name("_swift_os_log_default") +internal func _swift_os_log_default() -> OSLog + +@available(*, unavailable, renamed: "OSLogType.default") +public var OS_LOG_TYPE_DEFAULT: OSLogType { + fatalError() +} + +@available(*, unavailable, renamed: "OSLogType.info") +public var OS_LOG_TYPE_INFO: OSLogType { + fatalError() +} + +@available(*, unavailable, renamed: "OSLogType.debug") +public var OS_LOG_TYPE_DEBUG: OSLogType { + fatalError() +} + +@available(*, unavailable, renamed: "OSLogType.error") +public var OS_LOG_TYPE_ERROR: OSLogType { + fatalError() +} + +@available(*, unavailable, renamed: "OSLogType.fault") +public var OS_LOG_TYPE_FAULT: OSLogType { + fatalError() +} diff --git a/stdlib/public/SwiftShims/DispatchShims.h b/stdlib/public/SwiftShims/DispatchShims.h index 37c5bc2ebaf39..e5f1c5ba37026 100644 --- a/stdlib/public/SwiftShims/DispatchShims.h +++ b/stdlib/public/SwiftShims/DispatchShims.h @@ -40,10 +40,12 @@ namespace swift { extern "C" { typedef unsigned long __swift_shims_dispatch_block_flags_t; typedef unsigned int __swift_shims_qos_class_t; +typedef __swift_uint64_t __swift_shims_dispatch_time_t; typedef void (^__swift_shims_dispatch_block_t)(void); typedef id __swift_shims_dispatch_queue_t; typedef id __swift_shims_dispatch_group_t; typedef id __swift_shims_dispatch_data_t; +typedef id __swift_shims_dispatch_source_t; SWIFT_RUNTIME_STDLIB_INTERFACE SWIFT_DISPATCH_RETURNS_RETAINED @@ -90,12 +92,29 @@ void _swift_dispatch_sync( __swift_shims_dispatch_queue_t queue, __swift_shims_dispatch_block_t block); +SWIFT_RUNTIME_STDLIB_INTERFACE +void _swift_dispatch_barrier_async( + __swift_shims_dispatch_queue_t queue, + __swift_shims_dispatch_block_t block); + SWIFT_RUNTIME_STDLIB_INTERFACE void _swift_dispatch_group_async( __swift_shims_dispatch_group_t group, __swift_shims_dispatch_queue_t queue, __swift_shims_dispatch_block_t block); +SWIFT_RUNTIME_STDLIB_INTERFACE +void _swift_dispatch_group_notify( + __swift_shims_dispatch_group_t group, + __swift_shims_dispatch_queue_t queue, + __swift_shims_dispatch_block_t block); + +SWIFT_RUNTIME_STDLIB_INTERFACE +void _swift_dispatch_after( + __swift_shims_dispatch_time_t when, + __swift_shims_dispatch_queue_t queue, + __swift_shims_dispatch_block_t block); + SWIFT_RUNTIME_STDLIB_INTERFACE void _swift_dispatch_apply_current( unsigned int iterations, @@ -118,6 +137,21 @@ _swift_dispatch_data_apply( __swift_shims_dispatch_data_t data, __swift_shims_dispatch_data_applier SWIFT_DISPATCH_NOESCAPE applier); +SWIFT_RUNTIME_STDLIB_INTERFACE +void _swift_dispatch_source_set_event_handler( + __swift_shims_dispatch_source_t source, + __swift_shims_dispatch_block_t SWIFT_DISPATCH_NULLABLE block); + +SWIFT_RUNTIME_STDLIB_INTERFACE +void _swift_dispatch_source_set_cancel_handler( + __swift_shims_dispatch_source_t source, + __swift_shims_dispatch_block_t SWIFT_DISPATCH_NULLABLE block); + +SWIFT_RUNTIME_STDLIB_INTERFACE +void _swift_dispatch_source_set_registration_handler( + __swift_shims_dispatch_source_t source, + __swift_shims_dispatch_block_t SWIFT_DISPATCH_NULLABLE block); + #ifdef __cplusplus }} // extern "C", namespace swift #endif diff --git a/stdlib/public/core/ErrorType.swift b/stdlib/public/core/ErrorType.swift index d3a8ef43df31a..cb7b3453c8f1b 100644 --- a/stdlib/public/core/ErrorType.swift +++ b/stdlib/public/core/ErrorType.swift @@ -114,11 +114,22 @@ public protocol Error { var _domain: String { get } var _code: Int { get } var _userInfo: Any? { get } + +#if _runtime(_ObjC) + func _getEmbeddedNSError() -> AnyObject? +#endif } #if _runtime(_ObjC) -// Helper functions for the C++ runtime to have easy access to domain, -// code, and userInfo as Objective-C values. +extension Error { + /// Default implementation: there is no embedded NSError. + public func _getEmbeddedNSError() -> AnyObject? { return nil } +} +#endif + +#if _runtime(_ObjC) +// Helper functions for the C++ runtime to have easy access to embedded error, +// domain, code, and userInfo as Objective-C values. @_silgen_name("swift_stdlib_getErrorDomainNSString") public func _stdlib_getErrorDomainNSString(_ x: UnsafePointer) -> AnyObject { @@ -138,6 +149,19 @@ public func _stdlib_getErrorUserInfoNSDictionary(_ x: UnsafePointer( + _ x: UnsafePointer) -> AnyObject? { + return x.pointee._getEmbeddedNSError() +} + +/// FIXME: Quite unfortunate to have both of these. +@_silgen_name("swift_stdlib_getErrorEmbeddedNSError") +public func _stdlib_getErrorEmbeddedNSError(_ x: T) +-> AnyObject? { + return x._getEmbeddedNSError() +} + @_silgen_name("swift_stdlib_getErrorDefaultUserInfo") public func _stdlib_getErrorDefaultUserInfo(_ error: Error) -> AnyObject? diff --git a/stdlib/public/runtime/Casting.cpp b/stdlib/public/runtime/Casting.cpp index 96f600eb9c178..01f1372e07a3f 100644 --- a/stdlib/public/runtime/Casting.cpp +++ b/stdlib/public/runtime/Casting.cpp @@ -872,6 +872,16 @@ swift_dynamicCastMetatypeToObjectUnconditional(const Metadata *metatype) { } } } + +// @_silgen_name("swift_stdlib_getErrorEmbeddedNSErrorIndirect") +// public func _stdlib_getErrorEmbeddedNSErrorIndirect( +/// _ x: UnsafePointer) -> AnyObject? +SWIFT_CC(swift) +extern "C" id swift_stdlib_getErrorEmbeddedNSErrorIndirect( + const OpaqueValue *error, + const Metadata *T, + const WitnessTable *Error); + #endif /// Perform a dynamic cast to an existential type. @@ -1040,7 +1050,20 @@ static bool _dynamicCastToExistential(OpaqueValue *dest, targetType->Protocols, &errorWitness)) return _fail(src, srcType, targetType, flags, srcDynamicType); - + +#if SWIFT_OBJC_INTEROP + // Check whether there is an embedded NSError. If so, use that for our Error + // representation. + if (auto embedded = + swift_stdlib_getErrorEmbeddedNSErrorIndirect(srcDynamicValue, + srcDynamicType, + errorWitness)) { + *destBoxAddr = reinterpret_cast(embedded); + maybeDeallocateSourceAfterSuccess(); + return true; + } +#endif + BoxPair destBox = swift_allocError(srcDynamicType, errorWitness, srcDynamicValue, /*isTake*/ canTake && (flags & DynamicCastFlags::TakeOnSuccess)); @@ -2010,10 +2033,21 @@ static id dynamicCastValueToNSError(OpaqueValue *src, const Metadata *srcType, const WitnessTable *srcErrorWitness, DynamicCastFlags flags) { + // Check whether there is an embedded NSError. + if (auto embedded = + swift_stdlib_getErrorEmbeddedNSErrorIndirect(src, srcType, + srcErrorWitness)) { + if (flags & DynamicCastFlags::TakeOnSuccess) + srcType->vw_destroy(src); + + return embedded; + } + BoxPair errorBox = swift_allocError(srcType, srcErrorWitness, src, /*isTake*/ flags & DynamicCastFlags::TakeOnSuccess); return swift_bridgeErrorToNSError((SwiftError*)errorBox.first); } + #endif namespace { diff --git a/stdlib/public/runtime/ErrorObject.mm b/stdlib/public/runtime/ErrorObject.mm index 89c2dbb8d5370..2de9168ca1ab5 100644 --- a/stdlib/public/runtime/ErrorObject.mm +++ b/stdlib/public/runtime/ErrorObject.mm @@ -79,15 +79,10 @@ - (NSInteger)code { - (NSDictionary*)userInfo { auto error = (const SwiftError*)self; auto userInfo = error->userInfo.load(SWIFT_MEMORY_ORDER_CONSUME); - - if (userInfo) { - // Don't need to .retain.autorelease since it's immutable. - return (NSDictionary*)userInfo; - } else { - // -[NSError userInfo] never returns nil on OS X 10.8 or later. - NSDictionary *emptyDict = SWIFT_LAZY_CONSTANT(@{}); - return emptyDict; - } + assert(userInfo + && "Error box used as NSError before initialization"); + // Don't need to .retain.autorelease since it's immutable. + return (NSDictionary*)userInfo; } - (id)copyWithZone:(NSZone *)zone { @@ -319,8 +314,11 @@ typedef SWIFT_CC(swift) static id _swift_bridgeErrorToNSError_(SwiftError *errorObject) { auto ns = reinterpret_cast(errorObject); - // If we already have a domain set, then we've already initialized. - if (errorObject->domain.load(SWIFT_MEMORY_ORDER_CONSUME)) + // If we already have a domain and userInfo set, then we've already + // initialized. + // FIXME: This might be overly strict; can we look only at the domain? + if (errorObject->domain.load(std::memory_order_acquire) && + errorObject->userInfo.load(std::memory_order_acquire)) return ns; // Otherwise, calculate the domain and code (TODO: and user info), and @@ -334,6 +332,10 @@ static id _swift_bridgeErrorToNSError_(SwiftError *errorObject) { NSDictionary *userInfo = swift_stdlib_getErrorUserInfoNSDictionary(value, type, witness); + // Never produce an empty userInfo dictionary. + if (!userInfo) + userInfo = SWIFT_LAZY_CONSTANT(@{}); + // The error code shouldn't change, so we can store it blindly, even if // somebody beat us to it. The store can be relaxed, since we'll do a // store(release) of the domain last thing to publish the initialized diff --git a/stdlib/public/stubs/DispatchShims.mm b/stdlib/public/stubs/DispatchShims.mm index 697bab25bb0c1..e669288830162 100644 --- a/stdlib/public/stubs/DispatchShims.mm +++ b/stdlib/public/stubs/DispatchShims.mm @@ -94,6 +94,14 @@ dispatch_async(cast(queue), cast(block)); } +void +swift::_swift_dispatch_barrier_async( + __swift_shims_dispatch_queue_t queue, + __swift_shims_dispatch_block_t block) +{ + dispatch_barrier_async(cast(queue), cast(block)); +} + void swift::_swift_dispatch_group_async( __swift_shims_dispatch_group_t group, @@ -103,6 +111,15 @@ dispatch_group_async((dispatch_group_t)group, cast(queue), cast(block)); } +void +swift::_swift_dispatch_group_notify( + __swift_shims_dispatch_group_t group, + __swift_shims_dispatch_queue_t queue, + __swift_shims_dispatch_block_t block) +{ + dispatch_group_notify((dispatch_group_t)group, cast(queue), cast(block)); +} + void swift::_swift_dispatch_sync( __swift_shims_dispatch_queue_t queue, @@ -111,6 +128,15 @@ dispatch_sync(cast(queue), cast(block)); } +void +swift::_swift_dispatch_after( + __swift_shims_dispatch_time_t when, + __swift_shims_dispatch_queue_t queue, + __swift_shims_dispatch_block_t block) +{ + dispatch_after((dispatch_time_t)when, cast(queue), cast(block)); +} + void swift::_swift_dispatch_apply_current( unsigned int iterations, @@ -140,3 +166,27 @@ void SWIFT_DISPATCH_NOESCAPE (^block)(long)) return applier(data, off, loc, size); }); } + +void +swift::_swift_dispatch_source_set_event_handler( + __swift_shims_dispatch_source_t source, + __swift_shims_dispatch_block_t block) +{ + dispatch_source_set_event_handler((dispatch_source_t)source, cast(block)); +} + +void +swift::_swift_dispatch_source_set_cancel_handler( + __swift_shims_dispatch_source_t source, + __swift_shims_dispatch_block_t block) +{ + dispatch_source_set_cancel_handler((dispatch_source_t)source, cast(block)); +} + +void +swift::_swift_dispatch_source_set_registration_handler( + __swift_shims_dispatch_source_t source, + __swift_shims_dispatch_block_t block) +{ + dispatch_source_set_registration_handler((dispatch_source_t)source, cast(block)); +} diff --git a/test/1_stdlib/ArrayTraps.swift.gyb b/test/1_stdlib/ArrayTraps.swift.gyb index 638a8cc16fa68..6260ae427f189 100644 --- a/test/1_stdlib/ArrayTraps.swift.gyb +++ b/test/1_stdlib/ArrayTraps.swift.gyb @@ -10,6 +10,7 @@ import StdlibUnittest +let testSuiteSuffix = _isDebugAssertConfiguration() ? "_debug" : "_release" %{ # We test for bounds-checking traps for both reading and writing @@ -27,7 +28,7 @@ def bounds_trap(index, expr_to_write): % for ArrayTy in array_types: -var ${ArrayTy}Traps = TestSuite("${ArrayTy}Traps") +var ${ArrayTy}Traps = TestSuite("${ArrayTy}Traps" + testSuiteSuffix) % for io in ['read', 'write']: diff --git a/test/1_stdlib/ArrayTrapsObjC.swift.gyb b/test/1_stdlib/ArrayTrapsObjC.swift.gyb index 3d4164a6f8349..07c1dc444c6ca 100644 --- a/test/1_stdlib/ArrayTrapsObjC.swift.gyb +++ b/test/1_stdlib/ArrayTrapsObjC.swift.gyb @@ -10,11 +10,11 @@ // REQUIRES: objc_interop import StdlibUnittest - - import Foundation -var ArrayTraps = TestSuite("ArrayTraps") +let testSuiteSuffix = _isDebugAssertConfiguration() ? "_debug" : "_release" + +var ArrayTraps = TestSuite("ArrayTraps" + testSuiteSuffix) class Base { } class Derived : Base { } @@ -88,7 +88,7 @@ ArrayTraps.test("bounds_with_downcast") let x = da[2] } -var ArraySemanticOptzns = TestSuite("ArraySemanticOptzns") +var ArraySemanticOptzns = TestSuite("ArraySemanticOptzns" + testSuiteSuffix) class BaseClass { } diff --git a/test/1_stdlib/CharacterTraps.swift b/test/1_stdlib/CharacterTraps.swift index fc236260a1f0b..bf1422145caa1 100644 --- a/test/1_stdlib/CharacterTraps.swift +++ b/test/1_stdlib/CharacterTraps.swift @@ -9,8 +9,9 @@ import StdlibUnittest +let testSuiteSuffix = _isDebugAssertConfiguration() ? "_debug" : "_release" -var CharacterTraps = TestSuite("CharacterTraps") +var CharacterTraps = TestSuite("CharacterTraps" + testSuiteSuffix) CharacterTraps.test("CharacterFromEmptyString") .skip(.custom( diff --git a/test/1_stdlib/DictionaryTraps.swift b/test/1_stdlib/DictionaryTraps.swift index 504c755058438..66cf7b359eb5e 100644 --- a/test/1_stdlib/DictionaryTraps.swift +++ b/test/1_stdlib/DictionaryTraps.swift @@ -9,7 +9,9 @@ import StdlibUnittest -var DictionaryTraps = TestSuite("DictionaryTraps") +let testSuiteSuffix = _isDebugAssertConfiguration() ? "_debug" : "_release" + +var DictionaryTraps = TestSuite("DictionaryTraps" + testSuiteSuffix) DictionaryTraps.test("DuplicateKeys1") .skip(.custom( diff --git a/test/1_stdlib/DictionaryTrapsObjC.swift b/test/1_stdlib/DictionaryTrapsObjC.swift index 96a7c207ec4c3..7ee4f3d9e9352 100644 --- a/test/1_stdlib/DictionaryTrapsObjC.swift +++ b/test/1_stdlib/DictionaryTrapsObjC.swift @@ -11,7 +11,9 @@ import StdlibUnittest import Foundation -var DictionaryTraps = TestSuite("DictionaryTraps") +let testSuiteSuffix = _isDebugAssertConfiguration() ? "_debug" : "_release" + +var DictionaryTraps = TestSuite("DictionaryTraps" + testSuiteSuffix) struct NotBridgedKeyTy : Equatable, Hashable { init(_ value: Int) { diff --git a/test/1_stdlib/Dispatch.swift b/test/1_stdlib/Dispatch.swift index 8b9b8e94fdbb5..025420d1468a1 100644 --- a/test/1_stdlib/Dispatch.swift +++ b/test/1_stdlib/Dispatch.swift @@ -3,6 +3,9 @@ // REQUIRES: objc_interop +// rdar://27226313 +// REQUIRES: optimized_stdlib + import Dispatch import Foundation import StdlibUnittest diff --git a/test/1_stdlib/ErrorBridged.swift b/test/1_stdlib/ErrorBridged.swift index 65b82fc974889..140f545b49e01 100644 --- a/test/1_stdlib/ErrorBridged.swift +++ b/test/1_stdlib/ErrorBridged.swift @@ -582,4 +582,75 @@ ErrorBridgingTests.test("Customizing localization/recovery laziness") { } } +class MyNSError : NSError { } + +ErrorBridgingTests.test("NSError subclass identity") { + let myNSError: Error = MyNSError(domain: "MyNSError", code: 0, userInfo: [:]) + let nsError = myNSError as NSError + expectTrue(type(of: nsError) == MyNSError.self) +} + +ErrorBridgingTests.test("Wrapped NSError identity") { + let nsError = NSError(domain: NSCocoaErrorDomain, + code: NSFileNoSuchFileError, + userInfo: [ + AnyHashable(NSFilePathErrorKey) : "/dev/null", + AnyHashable(NSStringEncodingErrorKey): /*ASCII=*/1, + ]) + + let error: Error = nsError + let nsError2: NSError = error as NSError + expectTrue(nsError === nsError2) + + // Extracting the NSError via the runtime. + let cocoaErrorAny: Any = error as! CocoaError + let nsError3: NSError = cocoaErrorAny as! NSError + expectTrue(nsError === nsError3) + + if let cocoaErrorAny2: Any = error as? CocoaError { + let nsError4: NSError = cocoaErrorAny2 as! NSError + expectTrue(nsError === nsError4) + } else { + expectUnreachable() + } + + // Extracting the NSError via direct call. + let cocoaError = error as! CocoaError + let nsError5: NSError = cocoaError as NSError + expectTrue(nsError === nsError5) + + if let cocoaError2 = error as? CocoaError { + let nsError6: NSError = cocoaError as NSError + expectTrue(nsError === nsError6) + } else { + expectUnreachable() + } +} + +extension Error { + func asNSError() -> NSError { + return self as NSError + } +} + +func unconditionalCast(_ x: Any, to: T.Type) -> T { + return x as! T +} + +func conditionalCast(_ x: Any, to: T.Type) -> T? { + return x as? T +} + +// SR-1562 +ErrorBridgingTests.test("Error archetype identity") { + let myError = NSError(domain: "myErrorDomain", code: 0, + userInfo: [ AnyHashable("one") : 1 ]) + expectTrue(myError === myError.asNSError()) + + expectTrue(unconditionalCast(myError, to: Error.self) as NSError + === myError) + expectTrue(conditionalCast(myError, to: Error.self)! as NSError + === myError) +} + runAllTests() diff --git a/test/1_stdlib/FloatingPoint.swift.gyb b/test/1_stdlib/FloatingPoint.swift.gyb index 1e004c7f28404..a8c68e7382531 100644 --- a/test/1_stdlib/FloatingPoint.swift.gyb +++ b/test/1_stdlib/FloatingPoint.swift.gyb @@ -289,6 +289,17 @@ FloatingPoint.test("${Self}.round") { for value in [${Self}(), 1, 1/${Self}.ulpOfOne, .greatestFiniteMagnitude, .infinity] { expectBitwiseEqual(value, value.rounded(rule)) + + // FIXME: rdar://27347596 + // Double -0 rounded toNearestOrEven is wrong on watchos armv7k +% if Self == 'Double': +#if os(watchOS) && arch(arm) + if (value == 0 && rule == .toNearestOrEven) { + continue + } +#endif +% end + expectBitwiseEqual(-value, (-value).rounded(rule)) } diff --git a/test/1_stdlib/GameplayKit.swift b/test/1_stdlib/GameplayKit.swift new file mode 100644 index 0000000000000..2422772e7950f --- /dev/null +++ b/test/1_stdlib/GameplayKit.swift @@ -0,0 +1,55 @@ +// RUN: %target-run-simple-swift +// REQUIRES: executable_test + +// REQUIRES: objc_interop +// UNSUPPORTED: OS=watchos + +import StdlibUnittest + + +import GameplayKit + +var GameplayKitTests = TestSuite("GameplayKit") + +if #available(OSX 10.12, iOS 10.0, tvOS 10.0, *) { + + // MARK: Doing GameplayKit Stuff + + GameplayKitTests.test("GKPath_float2") { + var vec: [float2] = [float2(3.0), float2(4.0)] + let path = GKPath(points: vec, radius: Float(30), cyclical: true) + expectEqual(path.numPoints, 2) + expectEqual(path.radius, Float(30)) + expectEqual(path.isCyclical, true) + } + GameplayKitTests.test("GKPath_float3") { + var vec: [float3] = [float3(3.0), float3(4.0)] + let path = GKPath(points: vec, radius: Float(30), cyclical: true) + expectEqual(path.numPoints, 2) + expectEqual(path.radius, Float(30)) + expectEqual(path.isCyclical, true) + } + GameplayKitTests.test("GKPolygonObstacle") { + var vec = [float2(3.0, 3.0), float2(3.0, -3.0), float2(-3.0, 3.0), float2(-3.0, -3.0)] + let obstacle = GKPolygonObstacle(points: vec) + expectEqual(obstacle.vertexCount, 4) + } + GameplayKitTests.test("GKEntity") { + @objc(MovementComponent) + class MovementComponent: GKComponent { + override func update(deltaTime seconds: TimeInterval) {} + override func didAddToEntity() {} + override func willRemoveFromEntity() {} + } + let comp = MovementComponent() + let entity = GKEntity() + entity.addComponent(comp) + expectEqual(entity.components.count, 1) + let grabbedComp = entity.component(ofType: MovementComponent.self) + expectEqual(grabbedComp, comp) + entity.removeComponent(ofType: MovementComponent.self) + expectEqual(entity.components.count, 0) + } +} + +runAllTests() diff --git a/test/1_stdlib/IntervalTraps.swift b/test/1_stdlib/IntervalTraps.swift index cab06a7ac86b5..cc02350ff2338 100644 --- a/test/1_stdlib/IntervalTraps.swift +++ b/test/1_stdlib/IntervalTraps.swift @@ -20,8 +20,9 @@ import StdlibUnittest +let testSuiteSuffix = _isDebugAssertConfiguration() ? "_debug" : "_release" -var IntervalTraps = TestSuite("IntervalTraps") +var IntervalTraps = TestSuite("IntervalTraps" + testSuiteSuffix) IntervalTraps.test("HalfOpen") .skip(.custom( diff --git a/test/1_stdlib/NSObject.swift b/test/1_stdlib/NSObject.swift index fe866bcd9106c..b487589b48493 100644 --- a/test/1_stdlib/NSObject.swift +++ b/test/1_stdlib/NSObject.swift @@ -2,6 +2,7 @@ // REQUIRES: executable_test // REQUIRES: objc_interop +// UNSUPPORTED: OS=watchos import Foundation diff --git a/test/1_stdlib/RangeTraps.swift b/test/1_stdlib/RangeTraps.swift index c1c54cef9be8d..b00da3dae0ccc 100644 --- a/test/1_stdlib/RangeTraps.swift +++ b/test/1_stdlib/RangeTraps.swift @@ -20,8 +20,9 @@ import StdlibUnittest +let testSuiteSuffix = _isDebugAssertConfiguration() ? "_debug" : "_release" -var RangeTraps = TestSuite("RangeTraps") +var RangeTraps = TestSuite("RangeTraps" + testSuiteSuffix) RangeTraps.test("HalfOpen") .skip(.custom( diff --git a/test/1_stdlib/Reflection_objc.swift b/test/1_stdlib/Reflection_objc.swift index 04fe6ceb2d9f6..b3673363f97b2 100644 --- a/test/1_stdlib/Reflection_objc.swift +++ b/test/1_stdlib/Reflection_objc.swift @@ -146,7 +146,7 @@ case _: print("got something else") } -let color = OSColor.black() +let color = OSColor.black switch PlaygroundQuickLook(reflecting: color) { case .color(let color2 as OSColor) where color === color2: print("got the expected quick look color") diff --git a/test/1_stdlib/SetTraps.swift b/test/1_stdlib/SetTraps.swift index b9f5b6c959fd8..42a3da1820f1d 100644 --- a/test/1_stdlib/SetTraps.swift +++ b/test/1_stdlib/SetTraps.swift @@ -9,8 +9,9 @@ import StdlibUnittest +let testSuiteSuffix = _isDebugAssertConfiguration() ? "_debug" : "_release" -var SetTraps = TestSuite("SetTraps") +var SetTraps = TestSuite("SetTraps" + testSuiteSuffix) SetTraps.test("RemoveInvalidIndex1") .skip(.custom( diff --git a/test/1_stdlib/SetTrapsObjC.swift b/test/1_stdlib/SetTrapsObjC.swift index ea826c39b4dfb..9bc070843f9d0 100644 --- a/test/1_stdlib/SetTrapsObjC.swift +++ b/test/1_stdlib/SetTrapsObjC.swift @@ -11,6 +11,7 @@ import StdlibUnittest import Foundation +let testSuiteSuffix = _isDebugAssertConfiguration() ? "_debug" : "_release" struct NotBridgedKeyTy : Equatable, Hashable { init(_ value: Int) { @@ -49,7 +50,7 @@ func == (lhs: BridgedVerbatimRefTy, rhs: BridgedVerbatimRefTy) -> Bool { assert(_isBridgedToObjectiveC(BridgedVerbatimRefTy.self)) assert(_isBridgedVerbatimToObjectiveC(BridgedVerbatimRefTy.self)) -var SetTraps = TestSuite("SetTraps") +var SetTraps = TestSuite("SetTraps" + testSuiteSuffix) SetTraps.test("sanity") { // Sanity checks. This code should not trap. diff --git a/test/1_stdlib/SpriteKit.swift b/test/1_stdlib/SpriteKit.swift deleted file mode 100644 index 9e279de38d279..0000000000000 --- a/test/1_stdlib/SpriteKit.swift +++ /dev/null @@ -1,43 +0,0 @@ -// RUN: %target-run-simple-swift | FileCheck %s -// REQUIRES: executable_test - -// REQUIRES: objc_interop - -// watchOS does not have SpriteKit. -// UNSUPPORTED: OS=watchos - -import Foundation -import SpriteKit - -// Check that the subscript is there. -@available(OSX,introduced: 10.10) -@available(iOS,introduced: 8.0) -@available(tvOS,introduced: 8.0) -@available(watchOS,introduced: 2.0) -func testSubscript(_ node: SKNode) { - var _: [SKNode] = node["me"] -} - -// SKColor is NSColor on OS X and UIColor on iOS. - -var r = CGFloat(0) -var g = CGFloat(0) -var b = CGFloat(0) -var a = CGFloat(0) -var color = SKColor.red() -color.getRed(&r, green:&g, blue:&b, alpha:&a) -print("color \(r) \(g) \(b) \(a)") -// CHECK: color 1.0 0.0 0.0 1.0 - -#if os(OSX) -func f(_ c: NSColor) { - print("colortastic") -} -#endif -#if os(iOS) || os(tvOS) -func f(_ c: UIColor) { - print("colortastic") -} -#endif -f(color) -// CHECK: colortastic diff --git a/test/1_stdlib/StringTraps.swift b/test/1_stdlib/StringTraps.swift index d6fa8c984ca9f..5fd32076fea41 100644 --- a/test/1_stdlib/StringTraps.swift +++ b/test/1_stdlib/StringTraps.swift @@ -9,8 +9,9 @@ import StdlibUnittest +let testSuiteSuffix = _isDebugAssertConfiguration() ? "_debug" : "_release" -var StringTraps = TestSuite("StringTraps") +var StringTraps = TestSuite("StringTraps" + testSuiteSuffix) StringTraps.test("startIndex/predecessor") .skip(.custom( diff --git a/test/1_stdlib/os.swift b/test/1_stdlib/os.swift new file mode 100644 index 0000000000000..6ab251d08ba6e --- /dev/null +++ b/test/1_stdlib/os.swift @@ -0,0 +1,20 @@ +// RUN: %target-run-simple-swift +// REQUIRES: executable_test + +// REQUIRES: objc_interop + +import os +import Foundation +import StdlibUnittest + +defer { runAllTests() } + +var osAPI = TestSuite("osAPI") + +if #available(OSX 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *) { + osAPI.test("log") { + os_log("test: %d", 42) + // FIXME: cast to NSString because of CVarArg does not work with String + os_log("test2: %2", "test" as! NSString) + } +} diff --git a/test/ClangModules/CoreGraphics_test.swift b/test/ClangModules/CoreGraphics_test.swift index f5f64f39d65f0..f90ef436a3af7 100644 --- a/test/ClangModules/CoreGraphics_test.swift +++ b/test/ClangModules/CoreGraphics_test.swift @@ -113,15 +113,13 @@ public func testRenames(transform: CGAffineTransform, context: CGContext, // CHECK: call void @CGContextTranslateCTM(%struct.CGContext* [[CONTEXT]], double {{1\.0+.*}}, double {{1\.0+.*}}) context.clip(to: rect) - context.clip(to: &rect, count: 2) context.clip(to: rect, mask: image) // CHECK: call void @CGContextClipToRect(%struct.CGContext* [[CONTEXT]], %struct.CGRect* byval nonnull align 8 %{{.*}}) -// CHECK: call void @CGContextClipToRects(%struct.CGContext* [[CONTEXT]], %struct.CGRect* nonnull %rect, i64 2) // CHECK: call void @CGContextClipToMask(%struct.CGContext* [[CONTEXT]], %struct.CGRect* byval nonnull align 8 %{{.*}}, %struct.CGImage* %{{.*}}) var slice = CGRect.zero var remainder = CGRect.zero - rect.divided(slice: &slice, remainder: &remainder, atDistance: CGFloat(2.0), + rect.__divided(slice: &slice, remainder: &remainder, atDistance: CGFloat(2.0), from: edge) assert((slice, remainder) == rect.divided(atDistance: CGFloat(2.0), from: edge)) diff --git a/test/Constraints/ErrorBridging.swift b/test/Constraints/ErrorBridging.swift index 18a23e029ac85..0309db2171d6e 100644 --- a/test/Constraints/ErrorBridging.swift +++ b/test/Constraints/ErrorBridging.swift @@ -68,3 +68,8 @@ extension Error { return self // expected-error{{cannot convert return expression of type 'Self' to return type 'NSError'}} } } + +// rdar://problem/27543121 +func throwErrorCode() throws { + throw FictionalServerError.meltedDown // expected-error{{thrown error code type 'FictionalServerError.Code' does not conform to 'Error'; construct an 'FictionalServerError' instance}}{{29-29=(}}{{40-40=)}} +} diff --git a/test/Driver/Dependencies/Inputs/crash-simple/crash.swift b/test/Driver/Dependencies/Inputs/crash-simple/crash.swift new file mode 100644 index 0000000000000..7e7daa298c540 --- /dev/null +++ b/test/Driver/Dependencies/Inputs/crash-simple/crash.swift @@ -0,0 +1,2 @@ +# Dependencies after compilation: +provides-top-level: [a] diff --git a/test/Driver/Dependencies/Inputs/crash-simple/main.swift b/test/Driver/Dependencies/Inputs/crash-simple/main.swift new file mode 100644 index 0000000000000..c6dd8d475b207 --- /dev/null +++ b/test/Driver/Dependencies/Inputs/crash-simple/main.swift @@ -0,0 +1,2 @@ +# Dependencies after compilation: +depends-top-level: [a] diff --git a/test/Driver/Dependencies/Inputs/crash-simple/other.swift b/test/Driver/Dependencies/Inputs/crash-simple/other.swift new file mode 100644 index 0000000000000..33392ce138612 --- /dev/null +++ b/test/Driver/Dependencies/Inputs/crash-simple/other.swift @@ -0,0 +1,2 @@ +# Dependencies after compilation: +depends-top-level: [!private a] diff --git a/test/Driver/Dependencies/Inputs/crash-simple/output.json b/test/Driver/Dependencies/Inputs/crash-simple/output.json new file mode 100644 index 0000000000000..1f7532dc86406 --- /dev/null +++ b/test/Driver/Dependencies/Inputs/crash-simple/output.json @@ -0,0 +1,17 @@ +{ + "./main.swift": { + "object": "./main.o", + "swift-dependencies": "./main.swiftdeps" + }, + "./crash.swift": { + "object": "./crash.o", + "swift-dependencies": "./crash.swiftdeps" + }, + "./other.swift": { + "object": "./other.o", + "swift-dependencies": "./other.swiftdeps" + }, + "": { + "swift-dependencies": "./main~buildrecord.swiftdeps" + } +} diff --git a/test/Driver/Dependencies/Inputs/fail-with-bad-deps/bad.swift b/test/Driver/Dependencies/Inputs/fail-with-bad-deps/bad.swift new file mode 100644 index 0000000000000..0f05e70d14710 --- /dev/null +++ b/test/Driver/Dependencies/Inputs/fail-with-bad-deps/bad.swift @@ -0,0 +1,4 @@ +# Dependencies after compilation: +provides-top-level: [bad] +interface-hash: "after" +garbage: "" diff --git a/test/Driver/Dependencies/Inputs/fail-with-bad-deps/bad.swiftdeps b/test/Driver/Dependencies/Inputs/fail-with-bad-deps/bad.swiftdeps new file mode 100644 index 0000000000000..923f6689ba1a5 --- /dev/null +++ b/test/Driver/Dependencies/Inputs/fail-with-bad-deps/bad.swiftdeps @@ -0,0 +1,3 @@ +# Dependencies before compilation: +provides-top-level: [bad] +interface-hash: "before" diff --git a/test/Driver/Dependencies/Inputs/fail-with-bad-deps/depends-on-bad.swift b/test/Driver/Dependencies/Inputs/fail-with-bad-deps/depends-on-bad.swift new file mode 100644 index 0000000000000..415ec3b051000 --- /dev/null +++ b/test/Driver/Dependencies/Inputs/fail-with-bad-deps/depends-on-bad.swift @@ -0,0 +1,3 @@ +# Dependencies after compilation: +depends-top-level: [bad] +interface-hash: "after" diff --git a/test/Driver/Dependencies/Inputs/fail-with-bad-deps/depends-on-bad.swiftdeps b/test/Driver/Dependencies/Inputs/fail-with-bad-deps/depends-on-bad.swiftdeps new file mode 100644 index 0000000000000..97afde93b75ca --- /dev/null +++ b/test/Driver/Dependencies/Inputs/fail-with-bad-deps/depends-on-bad.swiftdeps @@ -0,0 +1,3 @@ +# Dependencies before compilation: +depends-top-level: [bad] +interface-hash: "before" diff --git a/test/Driver/Dependencies/Inputs/fail-with-bad-deps/depends-on-main.swift b/test/Driver/Dependencies/Inputs/fail-with-bad-deps/depends-on-main.swift new file mode 100644 index 0000000000000..2b781b861cb7e --- /dev/null +++ b/test/Driver/Dependencies/Inputs/fail-with-bad-deps/depends-on-main.swift @@ -0,0 +1,3 @@ +# Dependencies after compilation: +depends-top-level: [main] +interface-hash: "after" diff --git a/test/Driver/Dependencies/Inputs/fail-with-bad-deps/depends-on-main.swiftdeps b/test/Driver/Dependencies/Inputs/fail-with-bad-deps/depends-on-main.swiftdeps new file mode 100644 index 0000000000000..cd50d25b878a7 --- /dev/null +++ b/test/Driver/Dependencies/Inputs/fail-with-bad-deps/depends-on-main.swiftdeps @@ -0,0 +1,3 @@ +# Dependencies before compilation: +depends-top-level: [main] +interface-hash: "before" diff --git a/test/Driver/Dependencies/Inputs/fail-with-bad-deps/main.swift b/test/Driver/Dependencies/Inputs/fail-with-bad-deps/main.swift new file mode 100644 index 0000000000000..5b5f8d7f3346f --- /dev/null +++ b/test/Driver/Dependencies/Inputs/fail-with-bad-deps/main.swift @@ -0,0 +1,3 @@ +# Dependencies after compilation: +provides-top-level: [main] +interface-hash: "after" diff --git a/test/Driver/Dependencies/Inputs/fail-with-bad-deps/main.swiftdeps b/test/Driver/Dependencies/Inputs/fail-with-bad-deps/main.swiftdeps new file mode 100644 index 0000000000000..0ec59e418937a --- /dev/null +++ b/test/Driver/Dependencies/Inputs/fail-with-bad-deps/main.swiftdeps @@ -0,0 +1,3 @@ +# Dependencies before compilation: +provides-top-level: [main] +interface-hash: "before" diff --git a/test/Driver/Dependencies/Inputs/fail-with-bad-deps/output.json b/test/Driver/Dependencies/Inputs/fail-with-bad-deps/output.json new file mode 100644 index 0000000000000..7078694c2f183 --- /dev/null +++ b/test/Driver/Dependencies/Inputs/fail-with-bad-deps/output.json @@ -0,0 +1,21 @@ +{ + "./main.swift": { + "object": "./main.o", + "swift-dependencies": "./main.swiftdeps" + }, + "./bad.swift": { + "object": "./bad.o", + "swift-dependencies": "./bad.swiftdeps" + }, + "./depends-on-main.swift": { + "object": "./depends-on-main.o", + "swift-dependencies": "./depends-on-main.swiftdeps" + }, + "./depends-on-bad.swift": { + "object": "./depends-on-bad.o", + "swift-dependencies": "./depends-on-bad.swiftdeps" + }, + "": { + "swift-dependencies": "./main~buildrecord.swiftdeps" + } +} diff --git a/test/Driver/Dependencies/Inputs/update-dependencies-bad.py b/test/Driver/Dependencies/Inputs/update-dependencies-bad.py index 058428df7f65f..530ba73080955 100755 --- a/test/Driver/Dependencies/Inputs/update-dependencies-bad.py +++ b/test/Driver/Dependencies/Inputs/update-dependencies-bad.py @@ -11,23 +11,38 @@ # # ---------------------------------------------------------------------------- # -# Fails if the input file is named "bad.swift"; otherwise dispatches to -# update-dependencies.py. +# Fails if the input file is named "bad.swift" or "crash.swift"; otherwise +# dispatches to update-dependencies.py. "crash.swift" gives an exit code +# other than 1. # # ---------------------------------------------------------------------------- from __future__ import print_function import os +import shutil import sys assert sys.argv[1] == '-frontend' primaryFile = sys.argv[sys.argv.index('-primary-file') + 1] -if os.path.basename(primaryFile) == 'bad.swift': +if (os.path.basename(primaryFile) == 'bad.swift' or + os.path.basename(primaryFile) == 'crash.swift'): print("Handled", os.path.basename(primaryFile)) - sys.exit(1) + + # Replace the dependencies file with the input file. + try: + depsFile = sys.argv[sys.argv.index( + '-emit-reference-dependencies-path') + 1] + shutil.copyfile(primaryFile, depsFile) + except ValueError: + pass + + if os.path.basename(primaryFile) == 'bad.swift': + sys.exit(1) + else: + sys.exit(129) dir = os.path.dirname(os.path.abspath(__file__)) execfile(os.path.join(dir, "update-dependencies.py")) diff --git a/test/Driver/Dependencies/bindings-build-record-options.swift b/test/Driver/Dependencies/bindings-build-record-options.swift index 83a630f36ea6e..cffc3f1ab3442 100644 --- a/test/Driver/Dependencies/bindings-build-record-options.swift +++ b/test/Driver/Dependencies/bindings-build-record-options.swift @@ -1,12 +1,17 @@ // RUN: rm -rf %t && cp -r %S/Inputs/bindings-build-record/ %t // RUN: touch -t 201401240005 %t/* -// RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=MUST-EXEC +// RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=MUST-EXEC-INITIAL -// MUST-EXEC-NOT: warning -// MUST-EXEC: inputs: ["./main.swift"], output: {{[{].*[}]}}, condition: run-without-cascading -// MUST-EXEC: inputs: ["./other.swift"], output: {{[{].*[}]}}, condition: run-without-cascading -// MUST-EXEC: inputs: ["./yet-another.swift"], output: {{[{].*[}]}}, condition: run-without-cascading +// MUST-EXEC-INITIAL-NOT: warning +// MUST-EXEC-INITIAL: inputs: ["./main.swift"], output: {{[{].*[}]}}, condition: run-without-cascading +// MUST-EXEC-INITIAL: inputs: ["./other.swift"], output: {{[{].*[}]}}, condition: run-without-cascading +// MUST-EXEC-INITIAL: inputs: ["./yet-another.swift"], output: {{[{].*[}]}}, condition: run-without-cascading + +// MUST-EXEC-ALL-NOT: warning +// MUST-EXEC-ALL: inputs: ["./main.swift"], output: {{[{].*[}]$}} +// MUST-EXEC-ALL: inputs: ["./other.swift"], output: {{[{].*[}]$}} +// MUST-EXEC-ALL: inputs: ["./yet-another.swift"], output: {{[{].*[}]$}} // RUN: cd %t && %swiftc_driver -c -module-name main -driver-use-frontend-path %S/Inputs/update-dependencies.py ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json // RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=NO-EXEC @@ -19,28 +24,28 @@ // RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings -serialize-diagnostics ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=NO-EXEC // RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=NO-EXEC -// RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -O -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=MUST-EXEC +// RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -O -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=MUST-EXEC-ALL // RUN: cd %t && %swiftc_driver -c -module-name main -driver-use-frontend-path %S/Inputs/update-dependencies.py ./main.swift ./other.swift ./yet-another.swift -incremental -O -output-file-map %t/output.json // RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -O -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=NO-EXEC // RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -O -serialize-diagnostics -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=NO-EXEC -// RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -Onone -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=MUST-EXEC +// RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -Onone -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=MUST-EXEC-ALL // RUN: cd %t && %swiftc_driver -c -module-name main -driver-use-frontend-path %S/Inputs/update-dependencies.py ./main.swift ./other.swift ./yet-another.swift -incremental -Onone -output-file-map %t/output.json // RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -Onone -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=NO-EXEC -// RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=MUST-EXEC +// RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=MUST-EXEC-ALL // RUN: cd %t && %swiftc_driver -c -module-name main -driver-use-frontend-path %S/Inputs/update-dependencies.py ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json // RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=NO-EXEC -// RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -I. -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=MUST-EXEC +// RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -I. -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=MUST-EXEC-ALL // RUN: cd %t && %swiftc_driver -c -module-name main -driver-use-frontend-path %S/Inputs/update-dependencies.py ./main.swift ./other.swift ./yet-another.swift -incremental -I. -output-file-map %t/output.json // RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -I. -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=NO-EXEC -// RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -I. -I/ -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=MUST-EXEC +// RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -I. -I/ -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=MUST-EXEC-ALL // RUN: cd %t && %swiftc_driver -c -module-name main -driver-use-frontend-path %S/Inputs/update-dependencies.py ./main.swift ./other.swift ./yet-another.swift -incremental -I. -I/ -output-file-map %t/output.json // RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -I. -I/ -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=NO-EXEC -// RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -I. -DDEBUG -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=MUST-EXEC +// RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -I. -DDEBUG -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=MUST-EXEC-ALL // RUN: cd %t && %swiftc_driver -c -module-name main -driver-use-frontend-path %S/Inputs/update-dependencies.py ./main.swift ./other.swift ./yet-another.swift -incremental -I. -DDEBUG -output-file-map %t/output.json // RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -I. -DDEBUG -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=NO-EXEC // RUN: cd %t && %swiftc_driver -c -module-name main -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -DDEBUG -I. -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=NO-EXEC diff --git a/test/Driver/Dependencies/bindings-build-record.swift b/test/Driver/Dependencies/bindings-build-record.swift index c4d6ced29fbff..c9fa63a75b692 100644 --- a/test/Driver/Dependencies/bindings-build-record.swift +++ b/test/Driver/Dependencies/bindings-build-record.swift @@ -37,10 +37,15 @@ // RUN: %S/Inputs/touch.py 443865900 %t/* // RUN: cd %t && %swiftc_driver -driver-print-bindings ./main.swift ./other.swift -incremental -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=FILE-REMOVED -// FILE-REMOVED: inputs: ["./main.swift"], output: {{[{].*[}]}}, condition: run-without-cascading -// FILE-REMOVED: inputs: ["./other.swift"], output: {{[{].*[}]}}, condition: run-without-cascading +// FILE-REMOVED: inputs: ["./main.swift"], output: {{[{].*[}]$}} +// FILE-REMOVED: inputs: ["./other.swift"], output: {{[{].*[}]$}} // FILE-REMOVED-NOT: yet-another.swift // RUN: echo '{version: "bogus", inputs: {"./main.swift": [443865900, 0], "./other.swift": !private [443865900, 0], "./yet-another.swift": !dirty [443865900, 0]}}' > %t/main~buildrecord.swiftdeps -// RUN: cd %t && %swiftc_driver -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=MUST-EXEC +// RUN: cd %t && %swiftc_driver -driver-print-bindings ./main.swift ./other.swift ./yet-another.swift -incremental -output-file-map %t/output.json 2>&1 | FileCheck %s -check-prefix=INVALID-RECORD + +// INVALID-RECORD-NOT: warning +// INVALID-RECORD: inputs: ["./main.swift"], output: {{[{].*[}]$}} +// INVALID-RECORD: inputs: ["./other.swift"], output: {{[{].*[}]$}} +// INVALID-RECORD: inputs: ["./yet-another.swift"], output: {{[{].*[}]$}} diff --git a/test/Driver/Dependencies/crash-added.swift b/test/Driver/Dependencies/crash-added.swift new file mode 100644 index 0000000000000..1f4f9786b6585 --- /dev/null +++ b/test/Driver/Dependencies/crash-added.swift @@ -0,0 +1,30 @@ +/// crash ==> main | crash --> other + +// RUN: rm -rf %t && cp -r %S/Inputs/crash-simple/ %t +// RUN: touch -t 201401240005 %t/* + +// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck -check-prefix=CHECK-INITIAL %s + +// CHECK-INITIAL-NOT: warning +// CHECK-INITIAL: Handled main.swift +// CHECK-INITIAL: Handled other.swift + +// RUN: cd %t && not %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies-bad.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./other.swift ./crash.swift -module-name main -j1 -v 2>&1 | FileCheck -check-prefix=CHECK-ADDED %s +// RUN: FileCheck -check-prefix=CHECK-RECORD-ADDED %s < %t/main~buildrecord.swiftdeps + +// CHECK-ADDED-NOT: Handled +// CHECK-ADDED: Handled crash.swift +// CHECK-ADDED-NOT: Handled + +// CHECK-RECORD-ADDED-DAG: "./crash.swift": !dirty [ +// CHECK-RECORD-ADDED-DAG: "./main.swift": [ +// CHECK-RECORD-ADDED-DAG: "./other.swift": [ + + +// RUN: rm -rf %t && cp -r %S/Inputs/crash-simple/ %t +// RUN: touch -t 201401240005 %t/* + +// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck -check-prefix=CHECK-INITIAL %s + +// RUN: cd %t && not %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies-bad.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./crash.swift ./main.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck -check-prefix=CHECK-ADDED %s +// RUN: FileCheck -check-prefix=CHECK-RECORD-ADDED %s < %t/main~buildrecord.swiftdeps diff --git a/test/Driver/Dependencies/crash-new.swift b/test/Driver/Dependencies/crash-new.swift new file mode 100644 index 0000000000000..4bb967c9edceb --- /dev/null +++ b/test/Driver/Dependencies/crash-new.swift @@ -0,0 +1,44 @@ +/// crash ==> main | crash --> other + +// RUN: rm -rf %t && cp -r %S/Inputs/crash-simple/ %t +// RUN: touch -t 201401240005 %t/* + +// RUN: cd %t && not %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies-bad.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./crash.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck %s +// CHECK-NOT: warning +// CHECK: Handled main.swift +// CHECK: Handled crash.swift +// CHECK-NOT: Handled other.swift + +// RUN: cd %t && not %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies-bad.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./crash.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck -check-prefix=CHECK-BAD-ONLY %s + +// CHECK-BAD-ONLY-NOT: warning +// CHECK-BAD-ONLY-NOT: Handled +// CHECK-BAD-ONLY: Handled crash.swift +// CHECK-BAD-ONLY-NOT: Handled + +// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./crash.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck -check-prefix=CHECK-OKAY %s +// CHECK-OKAY: Handled main.swift +// CHECK-OKAY: Handled crash.swift +// CHECK-OKAY: Handled other.swift +// CHECK-OKAY-NOT: Handled + +// RUN: touch -t 201401240006 %t/crash.swift +// RUN: rm %t/crash.swiftdeps +// RUN: cd %t && not %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies-bad.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./crash.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck %s + +// RUN: touch -t 201401240005 %t/* +// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./crash.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck -check-prefix=CHECK-OKAY-2 %s + +// CHECK-OKAY-2: Handled crash.swift +// CHECK-OKAY-2: Handled other.swift +// CHECK-OKAY-2: Handled main.swift + +// RUN: touch -t 201401240006 %t/main.swift +// RUN: rm %t/main.swiftdeps +// RUN: cd %t && not %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies-bad.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./crash.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck %s + +// RUN: touch -t 201401240005 %t/* +// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./crash.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck -check-prefix=CHECK-OKAY %s +// RUN: touch -t 201401240006 %t/other.swift +// RUN: rm %t/other.swiftdeps +// RUN: cd %t && not %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies-bad.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./crash.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck %s diff --git a/test/Driver/Dependencies/crash-simple.swift b/test/Driver/Dependencies/crash-simple.swift new file mode 100644 index 0000000000000..ce0eb9e04045f --- /dev/null +++ b/test/Driver/Dependencies/crash-simple.swift @@ -0,0 +1,23 @@ +/// crash ==> main | crash --> other + +// RUN: rm -rf %t && cp -r %S/Inputs/crash-simple/ %t +// RUN: touch -t 201401240005 %t/* + +// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./crash.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck -check-prefix=CHECK-FIRST %s + +// CHECK-FIRST-NOT: warning +// CHECK-FIRST: Handled main.swift +// CHECK-FIRST: Handled crash.swift +// CHECK-FIRST: Handled other.swift + +// RUN: touch -t 201401240006 %t/crash.swift +// RUN: cd %t && not %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies-bad.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./crash.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck -check-prefix=CHECK-SECOND %s +// RUN: FileCheck -check-prefix=CHECK-RECORD %s < %t/main~buildrecord.swiftdeps + +// CHECK-SECOND: Handled crash.swift +// CHECK-SECOND-NOT: Handled main.swift +// CHECK-SECOND-NOT: Handled other.swift + +// CHECK-RECORD-DAG: "./crash.swift": !dirty [ +// CHECK-RECORD-DAG: "./main.swift": !dirty [ +// CHECK-RECORD-DAG: "./other.swift": !private [ diff --git a/test/Driver/Dependencies/fail-added.swift b/test/Driver/Dependencies/fail-added.swift new file mode 100644 index 0000000000000..a333078fcfb5c --- /dev/null +++ b/test/Driver/Dependencies/fail-added.swift @@ -0,0 +1,30 @@ +/// bad ==> main | bad --> other + +// RUN: rm -rf %t && cp -r %S/Inputs/fail-simple/ %t +// RUN: touch -t 201401240005 %t/* + +// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck -check-prefix=CHECK-INITIAL %s + +// CHECK-INITIAL-NOT: warning +// CHECK-INITIAL: Handled main.swift +// CHECK-INITIAL: Handled other.swift + +// RUN: cd %t && not %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies-bad.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./other.swift ./bad.swift -module-name main -j1 -v 2>&1 | FileCheck -check-prefix=CHECK-ADDED %s +// RUN: FileCheck -check-prefix=CHECK-RECORD-ADDED %s < %t/main~buildrecord.swiftdeps + +// CHECK-ADDED-NOT: Handled +// CHECK-ADDED: Handled bad.swift +// CHECK-ADDED-NOT: Handled + +// CHECK-RECORD-ADDED-DAG: "./bad.swift": !dirty [ +// CHECK-RECORD-ADDED-DAG: "./main.swift": [ +// CHECK-RECORD-ADDED-DAG: "./other.swift": [ + + +// RUN: rm -rf %t && cp -r %S/Inputs/fail-simple/ %t +// RUN: touch -t 201401240005 %t/* + +// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck -check-prefix=CHECK-INITIAL %s + +// RUN: cd %t && not %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies-bad.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./bad.swift ./main.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck -check-prefix=CHECK-ADDED %s +// RUN: FileCheck -check-prefix=CHECK-RECORD-ADDED %s < %t/main~buildrecord.swiftdeps diff --git a/test/Driver/Dependencies/fail-interface-hash.swift b/test/Driver/Dependencies/fail-interface-hash.swift index 5db2975e87c68..392cc24f996a8 100644 --- a/test/Driver/Dependencies/fail-interface-hash.swift +++ b/test/Driver/Dependencies/fail-interface-hash.swift @@ -23,7 +23,7 @@ // CHECK-SECOND: Handled bad.swift // CHECK-SECOND-NOT: Handled depends -// CHECK-RECORD-DAG: "./bad.swift": !private [ +// CHECK-RECORD-DAG: "./bad.swift": !dirty [ // CHECK-RECORD-DAG: "./main.swift": [ // CHECK-RECORD-DAG: "./depends-on-main.swift": !dirty [ // CHECK-RECORD-DAG: "./depends-on-bad.swift": [ diff --git a/test/Driver/Dependencies/fail-new.swift b/test/Driver/Dependencies/fail-new.swift index f3e3251c5e95f..226098c69a8c0 100644 --- a/test/Driver/Dependencies/fail-new.swift +++ b/test/Driver/Dependencies/fail-new.swift @@ -9,19 +9,30 @@ // CHECK: Handled bad.swift // CHECK-NOT: Handled other.swift -// RUN: cd %t && not %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies-bad.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./bad.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck %s +// RUN: cd %t && not %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies-bad.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./bad.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck -check-prefix=CHECK-BAD-ONLY %s + +// CHECK-BAD-ONLY-NOT: warning +// CHECK-BAD-ONLY-NOT: Handled +// CHECK-BAD-ONLY: Handled bad.swift +// CHECK-BAD-ONLY-NOT: Handled // RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./bad.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck -check-prefix=CHECK-OKAY %s // CHECK-OKAY: Handled main.swift // CHECK-OKAY: Handled bad.swift // CHECK-OKAY: Handled other.swift +// CHECK-OKAY-NOT: Handled // RUN: touch -t 201401240006 %t/bad.swift // RUN: rm %t/bad.swiftdeps // RUN: cd %t && not %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies-bad.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./bad.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck %s // RUN: touch -t 201401240005 %t/* -// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./bad.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck -check-prefix=CHECK-OKAY %s +// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./bad.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck -check-prefix=CHECK-OKAY-2 %s + +// CHECK-OKAY-2: Handled bad.swift +// CHECK-OKAY-2: Handled other.swift +// CHECK-OKAY-2: Handled main.swift + // RUN: touch -t 201401240006 %t/main.swift // RUN: rm %t/main.swiftdeps // RUN: cd %t && not %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies-bad.py -output-file-map %t/output.json -incremental -driver-always-rebuild-dependents ./main.swift ./bad.swift ./other.swift -module-name main -j1 -v 2>&1 | FileCheck %s diff --git a/test/Driver/Dependencies/fail-with-bad-deps.swift b/test/Driver/Dependencies/fail-with-bad-deps.swift new file mode 100644 index 0000000000000..f7e535d89a7e9 --- /dev/null +++ b/test/Driver/Dependencies/fail-with-bad-deps.swift @@ -0,0 +1,47 @@ +/// main ==> depends-on-main | bad ==> depends-on-bad + +// RUN: rm -rf %t && cp -r %S/Inputs/fail-with-bad-deps/ %t +// RUN: touch -t 201401240005 %t/* + +// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies.py -output-file-map %t/output.json -incremental ./main.swift ./bad.swift ./depends-on-main.swift ./depends-on-bad.swift -module-name main -j1 -v 2>&1 | FileCheck -check-prefix=CHECK-FIRST %s + +// CHECK-FIRST-NOT: warning +// CHECK-FIRST: Handled main.swift +// CHECK-FIRST: Handled bad.swift +// CHECK-FIRST: Handled depends-on-main.swift +// CHECK-FIRST: Handled depends-on-bad.swift + +// Reset the .swiftdeps files. +// RUN: cp -r %S/Inputs/fail-with-bad-deps/*.swiftdeps %t + +// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies.py -output-file-map %t/output.json -incremental ./main.swift ./bad.swift ./depends-on-main.swift ./depends-on-bad.swift -module-name main -j1 -v 2>&1 | FileCheck -check-prefix=CHECK-NONE %s +// CHECK-NONE-NOT: Handled + +// Reset the .swiftdeps files. +// RUN: cp -r %S/Inputs/fail-with-bad-deps/*.swiftdeps %t + +// RUN: touch -t 201401240006 %t/bad.swift +// RUN: cd %t && %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies.py -output-file-map %t/output.json -incremental ./main.swift ./bad.swift ./depends-on-main.swift ./depends-on-bad.swift -module-name main -j1 -v 2>&1 | FileCheck -check-prefix=CHECK-BUILD-ALL %s + +// CHECK-BUILD-ALL-NOT: warning +// CHECK-BUILD-ALL: Handled bad.swift +// CHECK-BUILD-ALL-DAG: Handled main.swift +// CHECK-BUILD-ALL-DAG: Handled depends-on-main.swift +// CHECK-BUILD-ALL-DAG: Handled depends-on-bad.swift + +// Reset the .swiftdeps files. +// RUN: cp -r %S/Inputs/fail-with-bad-deps/*.swiftdeps %t + +// RUN: touch -t 201401240007 %t/bad.swift %t/main.swift +// RUN: cd %t && not %swiftc_driver -c -driver-use-frontend-path %S/Inputs/update-dependencies-bad.py -output-file-map %t/output.json -incremental ./main.swift ./bad.swift ./depends-on-main.swift ./depends-on-bad.swift -module-name main -j1 -v 2>&1 | FileCheck -check-prefix=CHECK-WITH-FAIL %s +// RUN: FileCheck -check-prefix=CHECK-RECORD %s < %t/main~buildrecord.swiftdeps + +// CHECK-WITH-FAIL: Handled main.swift +// CHECK-WITH-FAIL-NOT: Handled depends +// CHECK-WITH-FAIL: Handled bad.swift +// CHECK-WITH-FAIL-NOT: Handled depends + +// CHECK-RECORD-DAG: "./bad.swift": !private [ +// CHECK-RECORD-DAG: "./main.swift": [ +// CHECK-RECORD-DAG: "./depends-on-main.swift": !dirty [ +// CHECK-RECORD-DAG: "./depends-on-bad.swift": [ diff --git a/test/FixCode/fixits-apply.swift b/test/FixCode/fixits-apply.swift index 605ad30c84347..8ca67a065cc70 100644 --- a/test/FixCode/fixits-apply.swift +++ b/test/FixCode/fixits-apply.swift @@ -209,3 +209,15 @@ class NoSemi { enum Bar { case bar } var foo: .Bar = .bar } + +func fnWithClosure(c: @escaping ()->()) {} +func testescape(rec: ()->()) { + fnWithClosure { rec() } +} + +protocol Prot1 {} +protocol Prot2 { + associatedtype Ty = Prot1 +} +class Cls1 : Prot1 {} +func testwhere(_: T) {} diff --git a/test/FixCode/fixits-apply.swift.result b/test/FixCode/fixits-apply.swift.result index 7f0e35674c672..72d4a6f42536c 100644 --- a/test/FixCode/fixits-apply.swift.result +++ b/test/FixCode/fixits-apply.swift.result @@ -212,3 +212,15 @@ class NoSemi { enum Bar { case bar } var foo: .Bar = .bar } + +func fnWithClosure(c: @escaping ()->()) {} +func testescape(rec: @escaping ()->()) { + fnWithClosure { rec() } +} + +protocol Prot1 {} +protocol Prot2 { + associatedtype Ty = Prot1 +} +class Cls1 : Prot1 {} +func testwhere(_: T) where T.Ty == Cls1 {} diff --git a/test/IRGen/abi_v7k.swift b/test/IRGen/abi_v7k.swift index 62bcc533028ea..ee482ff886c6b 100644 --- a/test/IRGen/abi_v7k.swift +++ b/test/IRGen/abi_v7k.swift @@ -4,6 +4,9 @@ // REQUIRES: CPU=armv7k // REQUIRES: OS=watchos +// FIXME: rdar://27341290 IR and asm checks for testOpt() are failing +// XFAIL: * + // CHECK-LABEL: define hidden float @_TF8test_v7k9addFloats{{.*}}(float, float) // CHECK: fadd float %0, %1 // CHECK ret float diff --git a/test/IRGen/c_layout.sil b/test/IRGen/c_layout.sil index 4fc0fa4ecf853..297d861d3d995 100644 --- a/test/IRGen/c_layout.sil +++ b/test/IRGen/c_layout.sil @@ -7,8 +7,8 @@ import Swift // TODO: Provide tests for other architectures -// CHECK-x86_64: %VSC11BitfieldOne = type <{ %Vs6UInt32, %VSC6Nested, [1 x i8], [4 x i8], [4 x i8], %Sf, [1 x i8], [7 x i8], %Vs6UInt64, %Vs6UInt32 }> -// CHECK-x86_64: %VSC6Nested = type <{ %Sf, [3 x i8] }> +// CHECK-x86_64: %VSC11BitfieldOne = type <{ %Vs6UInt32, %VSC6Nested, [4 x i8], [4 x i8], %Sf, [1 x i8], [7 x i8], %Vs6UInt64, %Vs6UInt32, [4 x i8] }> +// CHECK-x86_64: %VSC6Nested = type <{ %Sf, [3 x i8], [1 x i8] }> // CHECK-x86_64: %VSC26BitfieldSeparatorReference = type [[BITFIELD_SEP_TYPE:<{ %Vs5UInt8, \[3 x i8\], %Vs5UInt8 }>]] // CHECK-x86_64: %VSC25BitfieldSeparatorSameName = type [[BITFIELD_SEP_TYPE]] @@ -42,22 +42,22 @@ bb0: // CHECK-x86_64: [[ADDR_B_YZ:%.*]] = getelementptr inbounds %VSC6Nested, %VSC6Nested* [[ADDR_B]], i32 0, i32 1 // CHECK-x86_64: [[ADDR_B_YZ_1:%.*]] = bitcast [3 x i8]* [[ADDR_B_YZ]] to i24* // CHECK-x86_64: [[B_YZ:%.*]] = load i24, i24* [[ADDR_B_YZ_1]], align 4 -// CHECK-x86_64: [[ADDR_CDE:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[RESULT]], i32 0, i32 3 +// CHECK-x86_64: [[ADDR_CDE:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[RESULT]], i32 0, i32 2 // CHECK-x86_64: [[ADDR_CDE_1:%.*]] = bitcast [4 x i8]* [[ADDR_CDE]] to i32* // CHECK-x86_64: [[CDE:%.*]] = load i32, i32* [[ADDR_CDE_1]], align 4 -// CHECK-x86_64: [[ADDR_FGH:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[RESULT]], i32 0, i32 4 +// CHECK-x86_64: [[ADDR_FGH:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[RESULT]], i32 0, i32 3 // CHECK-x86_64: [[ADDR_FGH_1:%.*]] = bitcast [4 x i8]* [[ADDR_FGH]] to i32* // CHECK-x86_64: [[FGH:%.*]] = load i32, i32* [[ADDR_FGH_1]], align 8 -// CHECK-x86_64: [[ADDR_I:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[RESULT]], i32 0, i32 5 +// CHECK-x86_64: [[ADDR_I:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[RESULT]], i32 0, i32 4 // CHECK-x86_64: [[ADDR_I_V:%.*]] = getelementptr inbounds %Sf, %Sf* [[ADDR_I]], i32 0, i32 0 // CHECK-x86_64: [[I:%.*]] = load float, float* [[ADDR_I_V]], align 4 -// CHECK-x86_64: [[ADDR_JK:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[RESULT]], i32 0, i32 6 +// CHECK-x86_64: [[ADDR_JK:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[RESULT]], i32 0, i32 5 // CHECK-x86_64: [[ADDR_JK_1:%.*]] = bitcast [1 x i8]* [[ADDR_JK]] to i8* // CHECK-x86_64: [[JK:%.*]] = load i8, i8* [[ADDR_JK_1]], align 8 -// CHECK-x86_64: [[ADDR_L:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[RESULT]], i32 0, i32 8 +// CHECK-x86_64: [[ADDR_L:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[RESULT]], i32 0, i32 7 // CHECK-x86_64: [[ADDR_L_V:%.*]] = getelementptr inbounds %Vs6UInt64, %Vs6UInt64* [[ADDR_L]], i32 0, i32 0 // CHECK-x86_64: [[L:%.*]] = load i64, i64* [[ADDR_L_V]], align 8 -// CHECK-x86_64: [[ADDR_M:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[RESULT]], i32 0, i32 9 +// CHECK-x86_64: [[ADDR_M:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[RESULT]], i32 0, i32 8 // CHECK-x86_64: [[ADDR_M_V:%.*]] = getelementptr inbounds %Vs6UInt32, %Vs6UInt32* [[ADDR_M]], i32 0, i32 0 // CHECK-x86_64: [[M:%.*]] = load i32, i32* [[ADDR_M_V]], align 8 // Put all of the values into the indirect argument and make the second call. @@ -71,22 +71,22 @@ bb0: // CHECK-x86_64: [[ADDR_B_YZ:%.*]] = getelementptr inbounds %VSC6Nested, %VSC6Nested* [[ADDR_B]], i32 0, i32 1 // CHECK-x86_64: [[ADDR_B_YZ_1:%.*]] = bitcast [3 x i8]* [[ADDR_B_YZ]] to i24* // CHECK-x86_64: store i24 [[B_YZ]], i24* [[ADDR_B_YZ_1]], align 4 -// CHECK-x86_64: [[ADDR_CDE:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[ARG]], i32 0, i32 3 +// CHECK-x86_64: [[ADDR_CDE:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[ARG]], i32 0, i32 2 // CHECK-x86_64: [[ADDR_CDE_1:%.*]] = bitcast [4 x i8]* [[ADDR_CDE]] to i32* // CHECK-x86_64: store i32 [[CDE]], i32* [[ADDR_CDE_1]], align 4 -// CHECK-x86_64: [[ADDR_FGH:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[ARG]], i32 0, i32 4 +// CHECK-x86_64: [[ADDR_FGH:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[ARG]], i32 0, i32 3 // CHECK-x86_64: [[ADDR_FGH_1:%.*]] = bitcast [4 x i8]* [[ADDR_FGH]] to i32* // CHECK-x86_64: store i32 [[FGH]], i32* [[ADDR_FGH_1]], align 8 -// CHECK-x86_64: [[ADDR_I:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[ARG]], i32 0, i32 5 +// CHECK-x86_64: [[ADDR_I:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[ARG]], i32 0, i32 4 // CHECK-x86_64: [[ADDR_I_V:%.*]] = getelementptr inbounds %Sf, %Sf* [[ADDR_I]], i32 0, i32 0 // CHECK-x86_64: store float [[I]], float* [[ADDR_I_V]], align 4 -// CHECK-x86_64: [[ADDR_JK:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[ARG]], i32 0, i32 6 +// CHECK-x86_64: [[ADDR_JK:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[ARG]], i32 0, i32 5 // CHECK-x86_64: [[ADDR_JK_1:%.*]] = bitcast [1 x i8]* [[ADDR_JK]] to i8* // CHECK-x86_64: store i8 [[JK]], i8* [[ADDR_JK_1]], align 8 -// CHECK-x86_64: [[ADDR_L:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[ARG]], i32 0, i32 8 +// CHECK-x86_64: [[ADDR_L:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[ARG]], i32 0, i32 7 // CHECK-x86_64: [[ADDR_L_V:%.*]] = getelementptr inbounds %Vs6UInt64, %Vs6UInt64* [[ADDR_L]], i32 0, i32 0 // CHECK-x86_64: store i64 [[L]], i64* [[ADDR_L_V]], align 8 -// CHECK-x86_64: [[ADDR_M:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[ARG]], i32 0, i32 9 +// CHECK-x86_64: [[ADDR_M:%.*]] = getelementptr inbounds %VSC11BitfieldOne, %VSC11BitfieldOne* [[ARG]], i32 0, i32 8 // CHECK-x86_64: [[ADDR_M_V:%.*]] = getelementptr inbounds %Vs6UInt32, %Vs6UInt32* [[ADDR_M]], i32 0, i32 0 // CHECK-x86_64: store i32 [[M]], i32* [[ADDR_M_V]], align 8 // CHECK-x86_64: call void @consumeBitfieldOne(%VSC11BitfieldOne* byval align 8 [[ARG]]) diff --git a/test/Inputs/clang-importer-sdk/swift-modules/Foundation.swift b/test/Inputs/clang-importer-sdk/swift-modules/Foundation.swift index 3279206699e55..b429a29c5cf11 100644 --- a/test/Inputs/clang-importer-sdk/swift-modules/Foundation.swift +++ b/test/Inputs/clang-importer-sdk/swift-modules/Foundation.swift @@ -45,6 +45,24 @@ internal func _convertNSSetToSet(_ s: NSSet?) -> Set { return Set() } +extension AnyHashable : _ObjectiveCBridgeable { + public func _bridgeToObjectiveC() -> NSObject { + return NSObject() + } + public static func _forceBridgeFromObjectiveC(_ x: NSObject, + result: inout AnyHashable?) { + } + public static func _conditionallyBridgeFromObjectiveC( + _ x: NSObject, + result: inout AnyHashable? + ) -> Bool { + return true + } + public static func _unconditionallyBridgeFromObjectiveC(_ x: NSObject?) -> AnyHashable { + return AnyHashable("") + } +} + extension String : _ObjectiveCBridgeable { public func _bridgeToObjectiveC() -> NSString { return NSString() @@ -236,3 +254,76 @@ func _convertNSErrorToError(_ string: NSError?) -> Error @_silgen_name("swift_convertErrorToNSError") func _convertErrorToNSError(_ string: Error) -> NSError + +/// An internal protocol to represent Swift error enums that map to standard +/// Cocoa NSError domains. +public protocol _ObjectiveCBridgeableError : Error { + /// Produce a value of the error type corresponding to the given NSError, + /// or return nil if it cannot be bridged. + init?(_bridgedNSError: NSError) +} + +/// Describes a bridged error that stores the underlying NSError, so +/// it can be queried. +public protocol _BridgedStoredNSError : _ObjectiveCBridgeableError { + /// The type of an error code. + associatedtype Code: _ErrorCodeProtocol + + /// The error code for the given error. + var code: Code { get } + + //// Retrieves the embedded NSError. + var _nsError: NSError { get } + + /// Create a new instance of the error type with the given embedded + /// NSError. + /// + /// The \c error must have the appropriate domain for this error + /// type. + init(_nsError error: NSError) +} + +public protocol _ErrorCodeProtocol { + /// The corresponding error code. + associatedtype _ErrorType +} + +public extension _BridgedStoredNSError { + public init?(_bridgedNSError error: NSError) { + self.init(_nsError: error) + } +} + +/// Various helper implementations for _BridgedStoredNSError +public extension _BridgedStoredNSError + where Code: RawRepresentable, Code.RawValue: SignedInteger { + // FIXME: Generalize to Integer. + public var code: Code { + return Code(rawValue: numericCast(_nsError.code))! + } + + /// Initialize an error within this domain with the given ``code`` + /// and ``userInfo``. + public init(_ code: Code, userInfo: [String : Any] = [:]) { + self.init(_nsError: NSError(domain: "", code: 0, userInfo: [:])) + } + + /// The user-info dictionary for an error that was bridged from + /// NSError. + var userInfo: [String : Any] { return [:] } +} + +/// Various helper implementations for _BridgedStoredNSError +public extension _BridgedStoredNSError + where Code: RawRepresentable, Code.RawValue: UnsignedInteger { + // FIXME: Generalize to Integer. + public var code: Code { + return Code(rawValue: numericCast(_nsError.code))! + } + + /// Initialize an error within this domain with the given ``code`` + /// and ``userInfo``. + public init(_ code: Code, userInfo: [String : Any] = [:]) { + self.init(_nsError: NSError(domain: "", code: 0, userInfo: [:])) + } +} diff --git a/test/Inputs/clang-importer-sdk/usr/include/Foundation.h b/test/Inputs/clang-importer-sdk/usr/include/Foundation.h index 804f1fda655ab..5612f4c3ffbcb 100644 --- a/test/Inputs/clang-importer-sdk/usr/include/Foundation.h +++ b/test/Inputs/clang-importer-sdk/usr/include/Foundation.h @@ -1065,3 +1065,10 @@ static const NSClothingStyle NSClothingStyleOfficeCasual __attribute__((availabi void acceptError(NSError * _Nonnull error); NSError * _Nonnull produceError(void); NSError * _Nullable produceOptionalError(void); + +extern NSString * const FictionalServerErrorDomain; + +typedef enum __attribute__((ns_error_domain(FictionalServerErrorDomain))) FictionalServerErrorCode : NSInteger { + FictionalServerErrorMeltedDown = 1 +} FictionalServerErrorCode; + diff --git a/test/Interpreter/SDK/CALayer.swift b/test/Interpreter/SDK/CALayer.swift index e26d7c5b3b8c1..60360cc5ceb09 100644 --- a/test/Interpreter/SDK/CALayer.swift +++ b/test/Interpreter/SDK/CALayer.swift @@ -22,10 +22,10 @@ func hangCanary(_ o: AnyObject) { class FooLayer: CALayer { var black: CGColor - var white: CGColor = CGColor.constantColor(for: CGColor.white)! + var white: CGColor = CGColor.white override init() { - black = CGColor.constantColor(for: CGColor.black)! + black = CGColor.black super.init() hangCanary(self) } diff --git a/test/Interpreter/SDK/CGImportAsMember.swift b/test/Interpreter/SDK/CGImportAsMember.swift index 2ae15e8f9073e..51f5313641108 100644 --- a/test/Interpreter/SDK/CGImportAsMember.swift +++ b/test/Interpreter/SDK/CGImportAsMember.swift @@ -6,12 +6,9 @@ import Foundation import CoreGraphics class Colors { - // TODO: when issue is fixed, migrate these to CGColor class properties - static var black = CGColor.constantColor(for: CGColor.black)! - static var white = CGColor.constantColor(for: CGColor.white)! - - // FIXME: this triggers an assert in SILVerifier - static var clear = CGColor.constantColor(for: CGColor.clear)! + static var black = CGColor.black + static var white = CGColor.white + static var clear = CGColor.clear class func printColors() { print("Colors") // CHECK: Colors diff --git a/test/PrintAsObjC/Inputs/enums.h b/test/PrintAsObjC/Inputs/enums.h new file mode 100644 index 0000000000000..492cb8addb3e1 --- /dev/null +++ b/test/PrintAsObjC/Inputs/enums.h @@ -0,0 +1,23 @@ +// This file is meant to be used with the mock SDK, not the real one. +#import + +#define SWIFT_NAME(X) __attribute__((swift_name(#X))) + +@interface Wrapper : NSObject +@end + +enum TopLevelRaw { TopLevelRawA }; +enum MemberRaw { MemberRawA } SWIFT_NAME(Wrapper.Raw); + +typedef enum { TopLevelAnonA } TopLevelAnon; +typedef enum { MemberAnonA } MemberAnon SWIFT_NAME(Wrapper.Anon); +typedef enum SWIFT_NAME(Wrapper.Anon2) { MemberAnon2A } MemberAnon2; + +typedef enum TopLevelTypedef { TopLevelTypedefA } TopLevelTypedef; +typedef enum SWIFT_NAME(Wrapper.Typedef) MemberTypedef { MemberTypedefA } MemberTypedef; + +typedef NS_ENUM(long, TopLevelEnum) { TopLevelEnumA }; +typedef NS_ENUM(long, MemberEnum) { MemberEnumA } SWIFT_NAME(Wrapper.Enum); + +typedef NS_OPTIONS(long, TopLevelOptions) { TopLevelOptionsA = 1 }; +typedef NS_OPTIONS(long, MemberOptions) { MemberOptionsA = 1} SWIFT_NAME(Wrapper.Options); diff --git a/test/PrintAsObjC/any_as_id.swift b/test/PrintAsObjC/any_as_id.swift index 2555a63d5cf06..42f9078bc7a30 100644 --- a/test/PrintAsObjC/any_as_id.swift +++ b/test/PrintAsObjC/any_as_id.swift @@ -16,7 +16,6 @@ // RUN: FileCheck %s < %t/any_as_id.h // RUN: %check-in-clang %t/any_as_id.h -// RUN: %check-in-clang -fno-modules -Qunused-arguments %t/any_as_id.h import Foundation @@ -25,33 +24,51 @@ import Foundation // CHECK-NEXT: @interface AnyAsIdTest : NSObject class AnyAsIdTest : NSObject { -// CHECK-NEXT: - (void)takesId:(id _Nonnull)x; - func takesId(_ x: Any) {} +// CHECK-NEXT: - (NSArray * _Nonnull)arrayOfAny:(NSArray * _Nonnull)x; + func arrayOfAny(_ x: [Any]) -> [Any] { return x } +// CHECK-NEXT: - (NSArray * _Nullable)arrayOfAnyPerhaps:(NSArray * _Nonnull)x; + func arrayOfAnyPerhaps(_ x: [Any]) -> [Any]? { return x } + +// CHECK-NEXT: - (NSDictionary * _Nonnull)dictionaryOfAny:(NSDictionary * _Nonnull)x; + func dictionaryOfAny(_ x: [AnyHashable: Any]) -> [AnyHashable: Any] { return x } +// CHECK-NEXT: - (void)dictionaryOfAnyKeys:(NSDictionary, NSString *> * _Nonnull)x; + func dictionaryOfAnyKeys(_ x: [AnyHashable: String]) {} +// CHECK-NEXT: - (NSDictionary * _Nullable)dictionaryOfAnyMayhap:(NSDictionary * _Nonnull)x; + func dictionaryOfAnyMayhap(_ x: [AnyHashable: Any]) -> [AnyHashable: Any]? { return x } +// CHECK-NEXT: - (void)dictionaryOfAnyValues:(NSDictionary * _Nonnull)x; + func dictionaryOfAnyValues(_ x: [String: Any]) {} // CHECK-NEXT: - (id _Nonnull)getAny; func getAny() -> Any { return 1 as Any } +// CHECK-NEXT: - (id _Nullable)getAnyConstructively; + func getAnyConstructively() -> Any? { return Optional(1 as Any) } +// CHECK-NEXT: - (id _Nullable)getAnyMaybe; + func getAnyMaybe() -> Any? { return nil } +// CHECK-NEXT: - (id _Nullable)getAnyProbably; + func getAnyProbably() -> Any? { return 1 as Any } // CHECK-NEXT: - (id _Nonnull)passThroughAny:(id _Nonnull)x; func passThroughAny(_ x: Any) -> Any { return x } +// CHECK-NEXT: - (id _Nullable)passThroughAnyMaybe:(id _Nullable)x; + func passThroughAnyMaybe(_ x: Any?) -> Any? { return x } + +// CHECK-NEXT: - (void)setOfAny:(NSSet * _Nonnull)x; + func setOfAny(_ x: Set) {} + +// CHECK-NEXT: - (void)takesId:(id _Nonnull)x; + func takesId(_ x: Any) {} // CHECK-NEXT: - (id _Nonnull)unwrapAny:(id _Nullable)x; func unwrapAny(_ x : Any?) -> Any { return x! } -// CHECK-NEXT: - (id _Nullable)getAnyMaybe; - func getAnyMaybe() -> Any? { return nil } -// CHECK-NEXT: - (id _Nullable)getAnyProbably; - func getAnyProbably() -> Any? { return 1 as Any } -// CHECK-NEXT: - (id _Nullable)passThroughAnyMaybe:(id _Nullable)x; - func passThroughAnyMaybe(_ x: Any?) -> Any? { return x } -// CHECK-NEXT: - (id _Nullable)getAnyConstructively; - func getAnyConstructively() -> Any? { return Optional(1 as Any) } // CHECK-NEXT: - (id _Nullable)wrapAny:(id _Nonnull)x; func wrapAny(_ x : Any) -> Any? { return x } // CHECK-NEXT: - (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER; - /* implicit inherited init() */ + /* implicit inherited init() */ + } // CHECK-NEXT: @end - +extension NSArray { func forceToExist() {} } diff --git a/test/PrintAsObjC/enums.swift b/test/PrintAsObjC/enums.swift index b574dd16a9f78..cd532c6eef730 100644 --- a/test/PrintAsObjC/enums.swift +++ b/test/PrintAsObjC/enums.swift @@ -1,7 +1,7 @@ // RUN: rm -rf %t // RUN: mkdir %t -// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-source-import -emit-module -emit-module-doc -o %t %s -disable-objc-attr-requires-foundation-module -// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -parse-as-library %t/enums.swiftmodule -parse -emit-objc-header-path %t/enums.h -import-objc-header %S/../Inputs/empty.h -disable-objc-attr-requires-foundation-module +// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-source-import -emit-module -emit-module-doc -o %t %s -import-objc-header %S/Inputs/enums.h -disable-objc-attr-requires-foundation-module +// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -parse-as-library %t/enums.swiftmodule -parse -emit-objc-header-path %t/enums.h -import-objc-header %S/Inputs/enums.h -disable-objc-attr-requires-foundation-module // RUN: FileCheck %s < %t/enums.h // RUN: FileCheck -check-prefix=NEGATIVE %s < %t/enums.h // RUN: %check-in-clang %t/enums.h @@ -21,6 +21,8 @@ import Foundation // CHECK-NEXT: - (enum NegativeValues)takeAndReturnEnum:(enum FooComments)foo; // CHECK-NEXT: - (void)acceptPlainEnum:(enum NSMalformedEnumMissingTypedef)_; // CHECK-NEXT: - (enum ObjcEnumNamed)takeAndReturnRenamedEnum:(enum ObjcEnumNamed)foo; +// CHECK-NEXT: - (void)acceptTopLevelImportedWithA:(enum TopLevelRaw)a b:(TopLevelEnum)b c:(TopLevelOptions)c d:(TopLevelTypedef)d e:(TopLevelAnon)e; +// CHECK-NEXT: - (void)acceptMemberImportedWithA:(enum MemberRaw)a b:(enum MemberEnum)b c:(MemberOptions)c d:(enum MemberTypedef)d e:(MemberAnon)e ee:(MemberAnon2)ee; // CHECK: @end @objc class AnEnumMethod { @objc func takeAndReturnEnum(_ foo: FooComments) -> NegativeValues { @@ -30,6 +32,9 @@ import Foundation @objc func takeAndReturnRenamedEnum(_ foo: EnumNamed) -> EnumNamed { return .A } + + @objc func acceptTopLevelImported(a: TopLevelRaw, b: TopLevelEnum, c: TopLevelOptions, d: TopLevelTypedef, e: TopLevelAnon) {} + @objc func acceptMemberImported(a: Wrapper.Raw, b: Wrapper.Enum, c: Wrapper.Options, d: Wrapper.Typedef, e: Wrapper.Anon, ee: Wrapper.Anon2) {} } // CHECK-LABEL: typedef SWIFT_ENUM_NAMED(NSInteger, ObjcEnumNamed, "EnumNamed") { diff --git a/test/Prototypes/CollectionTransformers.swift b/test/Prototypes/CollectionTransformers.swift index f322e0775ceb2..5940dc23428b7 100644 --- a/test/Prototypes/CollectionTransformers.swift +++ b/test/Prototypes/CollectionTransformers.swift @@ -12,6 +12,9 @@ // RUN: %target-run-stdlib-swift // REQUIRES: executable_test +// FIXME: This test runs very slowly on watchOS. +// UNSUPPORTED: OS=watchos + public enum ApproximateCount { case Unknown case Precise(IntMax) diff --git a/test/Reflection/typeref_decoding_imported.swift b/test/Reflection/typeref_decoding_imported.swift index 270fa9133d78c..2850bbce8e908 100644 --- a/test/Reflection/typeref_decoding_imported.swift +++ b/test/Reflection/typeref_decoding_imported.swift @@ -25,7 +25,7 @@ // CHECK-32: ============== // CHECK-32: - __C.MyCStruct: -// CHECK-32: Size: 9 +// CHECK-32: Size: 12 // CHECK-32: Alignment: 4 // CHECK-32: Stride: 12 // CHECK-32: NumExtraInhabitants: 0 @@ -43,7 +43,7 @@ // CHECK-32: NumExtraInhabitants: 0 // CHECK-i386: - __C.MyCStructWithBitfields: -// CHECK-i386: Size: 2 +// CHECK-i386: Size: 4 // CHECK-i386: Alignment: 4 // CHECK-i386: Stride: 4 // CHECK-i386: NumExtraInhabitants: 0 @@ -81,7 +81,7 @@ // CHECK-64: ============== // CHECK-64: - __C.MyCStruct: -// CHECK-64: Size: 17 +// CHECK-64: Size: 24 // CHECK-64: Alignment: 8 // CHECK-64: Stride: 24 // CHECK-64: NumExtraInhabitants: 0 @@ -99,7 +99,7 @@ // CHECK-64: NumExtraInhabitants: 0 // CHECK-64: - __C.MyCStructWithBitfields: -// CHECK-64: Size: 2 +// CHECK-64: Size: 4 // CHECK-64: Alignment: 4 // CHECK-64: Stride: 4 // CHECK-64: NumExtraInhabitants: 0 diff --git a/test/Reflection/typeref_lowering_imported.swift b/test/Reflection/typeref_lowering_imported.swift index f446d6aa9487f..e6e84304b10d6 100644 --- a/test/Reflection/typeref_lowering_imported.swift +++ b/test/Reflection/typeref_lowering_imported.swift @@ -7,13 +7,13 @@ V12TypeLowering9HasCTypes // CHECK: (struct TypeLowering.HasCTypes) -// CHECK-NEXT: (struct size=34 alignment=8 stride=40 num_extra_inhabitants=0 +// CHECK-NEXT: (struct size=44 alignment=8 stride=48 num_extra_inhabitants=0 // CHECK-NEXT: (field name=mcs offset=0 -// CHECK-NEXT: (builtin size=17 alignment=8 stride=24 num_extra_inhabitants=0)) -// CHECK-NEXT: (field name=mce offset=20 +// CHECK-NEXT: (builtin size=24 alignment=8 stride=24 num_extra_inhabitants=0)) +// CHECK-NEXT: (field name=mce offset=24 // CHECK-NEXT: (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=0)) -// CHECK-NEXT: (field name=mcu offset=24 +// CHECK-NEXT: (field name=mcu offset=32 // CHECK-NEXT: (builtin size=8 alignment=8 stride=8 num_extra_inhabitants=0)) -// CHECK-NEXT: (field name=mcsbf offset=32 -// CHECK-NEXT: (builtin size=2 alignment=4 stride=4 num_extra_inhabitants=0))) +// CHECK-NEXT: (field name=mcsbf offset=40 +// CHECK-NEXT: (builtin size=4 alignment=4 stride=4 num_extra_inhabitants=0))) diff --git a/test/SILGen/objc_error.swift b/test/SILGen/objc_error.swift index 4da389b7b61d3..3629204c073e1 100644 --- a/test/SILGen/objc_error.swift +++ b/test/SILGen/objc_error.swift @@ -95,3 +95,53 @@ func testProduceOptionalError() -> Error? { // CHECK: function_ref @swift_convertNSErrorToError return produceOptionalError(); } + +class MyNSError : NSError { + override init() { + super.init(domain: "MyNSError", code: 0, userInfo: [:]) + } +} + +// CHECK-LABEL: sil hidden @_TF10objc_error14eraseMyNSError +// CHECK-NOT: return +// CHECK: init_existential_ref +func eraseMyNSError() -> Error { + return MyNSError() +} + +// CHECK-LABEL: sil hidden @_TF10objc_error25eraseFictionalServerErrorFT_Ps5Error_ +func eraseFictionalServerError() -> Error { + // CHECK-NOT: return + // CHECK: [[NSERROR_GETTER:%[0-9]+]] = function_ref @_TFVSC20FictionalServerErrorg8_nsErrorCSo7NSError + // CHECK: [[NSERROR:%[0-9]+]] = apply [[NSERROR_GETTER]] + // CHECK: [[ERROR:%[0-9]+]] = init_existential_ref [[NSERROR]] + // CHECK: return [[ERROR]] + return FictionalServerError(.meltedDown) +} + +// SR-1562 +extension Error { + // CHECK-LABEL: sil hidden @_TFE10objc_errorPs5Error16convertToNSErrorfT_CSo7NSError + // CHECK: bb0([[SELF:%[0-9]+]] : $*Self) + func convertToNSError() -> NSError { + // CHECK: [[GET_EMBEDDED_FN:%[0-9]+]] = function_ref @swift_stdlib_getErrorEmbeddedNSError + // CHECK: [[EMBEDDED_RESULT_OPT:%[0-9]+]] = apply [[GET_EMBEDDED_FN]] + // CHECK: [[HAS_EMBEDDED_RESULT:%[0-9]+]] = select_enum [[EMBEDDED_RESULT_OPT]] : $Optional + // CHECK: cond_br [[HAS_EMBEDDED_RESULT]], [[SUCCESS:bb[0-9]+]], [[FAILURE:bb[0-9]+]] + + // CHECK: [[SUCCESS]]: + // CHECK: [[EMBEDDED_RESULT:%[0-9]+]] = unchecked_enum_data [[EMBEDDED_RESULT_OPT]] : $Optional, #Optional.some!enumelt.1 + // CHECK: [[EMBEDDED_NSERROR:%[0-9]+]] = unchecked_ref_cast [[EMBEDDED_RESULT]] : $AnyObject to $NSError + // CHECK: [[ERROR:%[0-9]+]] = init_existential_ref [[EMBEDDED_NSERROR]] : $NSError : $NSError, $Error + // CHECK: br [[CONTINUATION:bb[0-9]+]]([[ERROR]] : $Error) + + // CHECK: [[FAILURE]]: + // CHECK: [[ERROR_BOX:%[0-9]+]] = alloc_existential_box $Error, $Self + // CHECK: [[ERROR_PROJECTED:%[0-9]+]] = project_existential_box $Self in [[ERROR_BOX]] : $Error + // CHECK: copy_addr [[SELF]] to [initialization] [[ERROR_PROJECTED]] : $*Self + // CHECK: br [[CONTINUATION]]([[ERROR_BOX]] : $Error) + + // CHECK: [[CONTINUATION]]([[ERROR_ARG:%[0-9]+]] : $Error): + return self as NSError + } +} diff --git a/test/SILOptimizer/looprotate.sil b/test/SILOptimizer/looprotate.sil index a7268a9a8fa94..8f90f649b66b8 100644 --- a/test/SILOptimizer/looprotate.sil +++ b/test/SILOptimizer/looprotate.sil @@ -21,15 +21,22 @@ import Swift // CHECK: [[STRUCT:%.*]] = struct $Int32 ({{%.*}} : $Builtin.Int32) // CHECK: return [[STRUCT]] : $Int32 +protocol P { + func boo() -> Int64 +} + class Bar { + func boo() -> Int64 func foo() @objc func foo_objc() } sil @_TFC4main3Bar3foofS0_FT_T_ : $@convention(method) (@guaranteed Bar) -> () +sil @_TFC4main3Bar3boofS0_FT_T_ : $@convention(method) (@guaranteed Bar) -> Int64 sil @_TFC4main3Bar3foo_objcfS0_FT_T_ : $@convention(objc_method) (Bar) -> () sil_vtable Bar { + #Bar.boo!1: _TFC4main3Bar3boofS0_FT_T_ #Bar.foo!1: _TFC4main3Bar3foofS0_FT_T_ #Bar.foo_objc!1: _TFC4main3Bar3foofS0_FT_T_ } @@ -104,6 +111,45 @@ bb3 (%23 : $Builtin.Int32) : return %24 : $Int32 } +// The following function used to crash the compiler, because loop rotate +// could not properly handle the reference from witness_method to the +// archetype opened by open_existential_addr +// CHECK-LABEL: sil @looprotate_with_opened_archetype +// CHECK: return +sil @looprotate_with_opened_archetype : $@convention(thin) (Int32, @in P) -> Int32 { +bb0(%0 : $Int32, %25: $*P): + %1 = struct_extract %0 : $Int32, #Int32._value + %2 = integer_literal $Builtin.Int32, 0 + %30 = alloc_box $Bool + %30a = project_box %30 : $@box Bool + %40 = open_existential_addr %25 : $*P to $*@opened("C22498FA-CABF-11E5-B9A9-685B35C48C83") P + br bb1(%1 : $Builtin.Int32, %2 : $Builtin.Int32, %25: $*P, %30 : $@box Bool, %30a : $*Bool) + +bb1(%4 : $Builtin.Int32, %5 : $Builtin.Int32, %26: $*P, %31 : $@box Bool, %32 : $*Bool): + %111 = witness_method $@opened("C22498FA-CABF-11E5-B9A9-685B35C48C83") P, #P.boo!1, %40 : $*@opened("C22498FA-CABF-11E5-B9A9-685B35C48C83") P : $@convention(witness_method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64 + %122 = apply %111<@opened("C22498FA-CABF-11E5-B9A9-685B35C48C83") P>(%40) : $@convention(witness_method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> Int64 + %6 = struct $Int32 (%5 : $Builtin.Int32) + %8 = builtin "cmp_eq_Word"(%5 : $Builtin.Int32, %1 : $Builtin.Int32) : $Builtin.Int1 + cond_br %8, bb3, bb2 + +bb2: + %10 = integer_literal $Builtin.Int32, 1 + %12 = integer_literal $Builtin.Int1, -1 + %13 = builtin "sadd_with_overflow_Word"(%5 : $Builtin.Int32, %10 : $Builtin.Int32, %12 : $Builtin.Int1) : $(Builtin.Int32, Builtin.Int1) + %14 = tuple_extract %13 : $(Builtin.Int32, Builtin.Int1), 0 + %15 = enum $Optional, #Optional.some!enumelt.1, %6 : $Int32 + %16 = unchecked_enum_data %15 : $Optional, #Optional.some!enumelt.1 + %17 = struct_extract %16 : $Int32, #Int32._value + %19 = integer_literal $Builtin.Int1, -1 + %20 = builtin "sadd_with_overflow_Word"(%4 : $Builtin.Int32, %17 : $Builtin.Int32, %19 : $Builtin.Int1) : $(Builtin.Int32, Builtin.Int1) + %21 = tuple_extract %20 : $(Builtin.Int32, Builtin.Int1), 0 + br bb1(%21 : $Builtin.Int32, %14 : $Builtin.Int32, %26: $*P, %31 : $@box Bool, %32 : $*Bool) + +bb3: + %23 = struct $Int32 (%4 : $Builtin.Int32) + return %23 : $Int32 +} + // Don't assert on this loop. bb2 is bb1 loop's new header after rotation but // also bb2 loop's header. diff --git a/test/attr/attr_autoclosure.swift b/test/attr/attr_autoclosure.swift index 1323ebfb74175..5655b0f70c222 100644 --- a/test/attr/attr_autoclosure.swift +++ b/test/attr/attr_autoclosure.swift @@ -55,7 +55,9 @@ func overloadedEach(_ source: P, _ closure: @escaping () -> ()) { struct S : P2 { typealias Element = Int func each(_ closure: @autoclosure () -> ()) { - overloadedEach(self, closure) // expected-error {{invalid conversion from non-escaping function of type '@autoclosure () -> ()' to potentially escaping function type '() -> ()'}} + // expected-note@-1{{parameter 'closure' is implicitly non-escaping because it was declared @autoclosure}} + + overloadedEach(self, closure) // expected-error {{passing non-escaping parameter 'closure' to function expecting an @escaping closure}} } } @@ -87,7 +89,9 @@ class Sub : Super { func func12_sink(_ x: @escaping () -> Int) { } func func12a(_ x: @autoclosure () -> Int) { - func12_sink(x) // expected-error{{invalid conversion from non-escaping function of type '@autoclosure () -> Int' to potentially escaping function type '() -> Int'}} + // expected-note@-1{{parameter 'x' is implicitly non-escaping because it was declared @autoclosure}} + + func12_sink(x) // expected-error {{passing non-escaping parameter 'x' to function expecting an @escaping closure}} } func func12b(_ x: @autoclosure(escaping) () -> Int) { func12_sink(x) diff --git a/test/attr/attr_escaping.swift b/test/attr/attr_escaping.swift index 78739fe7ffda4..c9f2af6ea816a 100644 --- a/test/attr/attr_escaping.swift +++ b/test/attr/attr_escaping.swift @@ -7,3 +7,48 @@ func wrongParamType(a: @escaping Int) {} // expected-error {{@escaping attribute func conflictingAttrs(_ fn: @noescape @escaping () -> Int) {} // expected-error {{@escaping conflicts with @noescape}} func takesEscaping(_ fn: @escaping () -> Int) {} // ok + +func callEscapingWithNoEscape(_ fn: () -> Int) { + // expected-note@-1{{parameter 'fn' is implicitly non-escaping}} {{37-37=@escaping }} + // expected-note@-2{{parameter 'fn' is implicitly non-escaping}} {{37-37=@escaping }} + + takesEscaping(fn) // expected-error{{passing non-escaping parameter 'fn' to function expecting an @escaping closure}} + let _ = fn // expected-error{{non-escaping parameter 'fn' may only be called}} +} + +typealias IntSugar = Int +func callSugared(_ fn: () -> IntSugar) { + // expected-note@-1{{parameter 'fn' is implicitly non-escaping}} {{24-24=@escaping }} + + takesEscaping(fn) // expected-error{{passing non-escaping parameter 'fn' to function expecting an @escaping closure}} +} + +struct StoresClosure { + var closure : () -> Int + init(_ fn: () -> Int) { + // expected-note@-1{{parameter 'fn' is implicitly non-escaping}} {{14-14=@escaping }} + + closure = fn // expected-error{{assigning non-escaping parameter 'fn' to an @escaping closure}} + } + + func arrayPack(_ fn: () -> Int) -> [()->Int] { + // expected-note@-1{{parameter 'fn' is implicitly non-escaping}} {{24-24=@escaping }} + + return [fn] // expected-error{{using non-escaping parameter 'fn' in a context expecting an @escaping closure}} + } + + func arrayPack(_ fn: @escaping () -> Int, _ fn2 : () -> Int) -> [()->Int] { + // expected-note@-1{{parameter 'fn2' is implicitly non-escaping}} {{53-53=@escaping }} + + return [fn, fn2] // expected-error{{using non-escaping parameter 'fn2' in a context expecting an @escaping closure}} + } +} + +func takesEscapingBlock(_ fn: @escaping @convention(block) () -> Void) { + fn() +} +func callEscapingWithNoEscapeBlock(_ fn: () -> Void) { + // expected-note@-1{{parameter 'fn' is implicitly non-escaping}} {{42-42=@escaping }} + + takesEscapingBlock(fn) // expected-error{{passing non-escaping parameter 'fn' to function expecting an @escaping closure}} +} \ No newline at end of file diff --git a/test/attr/attr_noescape.swift b/test/attr/attr_noescape.swift index fd9f6a942a2ff..85cf0cfa1fcd4 100644 --- a/test/attr/attr_noescape.swift +++ b/test/attr/attr_noescape.swift @@ -13,6 +13,7 @@ func takesNoEscapeClosure(_ fn : () -> Int) { // expected-note@-1{{parameter 'fn' is implicitly non-escaping}} {{34-34=@escaping }} // expected-note@-2{{parameter 'fn' is implicitly non-escaping}} {{34-34=@escaping }} // expected-note@-3{{parameter 'fn' is implicitly non-escaping}} {{34-34=@escaping }} + // expected-note@-4{{parameter 'fn' is implicitly non-escaping}} {{34-34=@escaping }} takesNoEscapeClosure { 4 } // ok _ = fn() // ok @@ -32,7 +33,7 @@ func takesNoEscapeClosure(_ fn : () -> Int) { takesNoEscapeClosure(fn) // ok - doesEscape(fn) // expected-error {{invalid conversion from non-escaping function of type '() -> Int' to potentially escaping function type '() -> Int'}} + doesEscape(fn) // expected-error {{passing non-escaping parameter 'fn' to function expecting an @escaping closure}} takesGenericClosure(4, fn) // ok takesGenericClosure(4) { fn() } // ok. } @@ -254,8 +255,8 @@ func curriedFlatMap2(_ x: [A]) -> (@noescape (A) -> [B]) -> [B] { func bad(_ a : @escaping (Int)-> Int) -> Int { return 42 } func escapeNoEscapeResult(_ x: [Int]) -> (@noescape (Int) -> Int) -> Int { - return { f in - bad(f) // expected-error {{invalid conversion from non-escaping function of type '(Int) -> Int' to potentially escaping function type '(Int) -> Int'}} + return { f in // expected-note{{parameter 'f' is implicitly non-escaping}} + bad(f) // expected-error {{passing non-escaping parameter 'f' to function expecting an @escaping closure}} } } diff --git a/utils/build-presets.ini b/utils/build-presets.ini index 0103aa36e4cac..0f95798e1f1b1 100644 --- a/utils/build-presets.ini +++ b/utils/build-presets.ini @@ -36,6 +36,7 @@ build-ninja # Build static standard library because it is used # to build external projects. build-swift-static-stdlib +build-swift-static-sdk-overlay build-swift-stdlib-unittest-extra compiler-vendor=apple @@ -188,6 +189,7 @@ lto dash-dash build-swift-static-stdlib +build-swift-static-sdk-overlay # Don't run host tests for iOS, tvOS and watchOS platforms to make the build # faster. @@ -620,6 +622,7 @@ install-xctest install-prefix=/usr swift-install-components=autolink-driver;compiler;clang-builtin-headers;stdlib;swift-remote-mirror;sdk-overlay;license build-swift-static-stdlib +build-swift-static-sdk-overlay build-swift-stdlib-unittest-extra # Executes the lit tests for the installable package that is created @@ -683,6 +686,8 @@ install-xctest install-prefix=/usr swift-install-components=autolink-driver;compiler;clang-builtin-headers;stdlib;swift-remote-mirror;sdk-overlay;dev build-swift-static-stdlib +build-swift-static-sdk-overlay + skip-test-lldb # Executes the lit tests for the installable package that is created @@ -766,6 +771,7 @@ lldb-build-type=Release verbose-build build-ninja build-swift-static-stdlib +build-swift-static-sdk-overlay build-swift-stdlib-unittest-extra compiler-vendor=apple playgroundlogger-build-type=Release @@ -971,6 +977,7 @@ reconfigure compiler-vendor=apple swift-install-components=swift-remote-mirror install-destdir=%(install_destdir)s +install-symroot=%(install_symroot)s darwin-install-extract-symbols=1 skip-build-cmark skip-build-llvm @@ -978,7 +985,7 @@ skip-build-llbuild skip-build-swiftpm skip-build-benchmarks install-swift -install-prefix=/usr +install-prefix=%(install_toolchain_dir)s/usr build-swift-examples=0 build-swift-tools=0 build-swift-static-stdlib=0 diff --git a/utils/update-checkout-config.json b/utils/update-checkout-config.json index 0582edb1cad22..7718442f64087 100644 --- a/utils/update-checkout-config.json +++ b/utils/update-checkout-config.json @@ -155,7 +155,7 @@ } }, "swift-3.0-preview-5" : { - "aliases": ["swift-3.0-branch", "swift-3.0-preview-5-branch"], + "aliases": ["swift-3.0-preview-5-branch"], "repos": { "llvm": "swift-3.0-branch", "clang": "swift-3.0-branch", @@ -171,6 +171,24 @@ "swift-integration-tests": "swift-3.0-preview-5-branch", "swift-xcode-playground-support": "swift-3.0-preview-5-branch" } + }, + "swift-3.0-branch" : { + "aliases": ["swift-3.0-branch"], + "repos": { + "llvm": "swift-3.0-branch", + "clang": "swift-3.0-branch", + "swift": "swift-3.0-branch", + "lldb": "swift-3.0-branch", + "cmark": "swift-3.0-branch", + "llbuild": "swift-3.0-branch", + "swiftpm": "swift-3.0-branch", + "compiler-rt": "swift-3.0-branch", + "swift-corelibs-xctest": "swift-3.0-branch", + "swift-corelibs-foundation": "swift-3.0-branch", + "swift-corelibs-libdispatch": "swift-3.0-branch", + "swift-integration-tests": "swift-3.0-branch", + "swift-xcode-playground-support": "swift-3.0-branch" + } } } } diff --git a/validation-test/Driver/Dependencies/Inputs/rdar25405605/helper-1.swift b/validation-test/Driver/Dependencies/Inputs/rdar25405605/helper-1.swift new file mode 100644 index 0000000000000..ec20ab4aa0973 --- /dev/null +++ b/validation-test/Driver/Dependencies/Inputs/rdar25405605/helper-1.swift @@ -0,0 +1,13 @@ +enum Foo { + case one + case two +} + +func doSomething(_ value: Foo) { + switch value { + case .one: + print("Hello") + case .two: + print("Goodbye") + } +} diff --git a/validation-test/Driver/Dependencies/Inputs/rdar25405605/helper-2.swift b/validation-test/Driver/Dependencies/Inputs/rdar25405605/helper-2.swift new file mode 100644 index 0000000000000..056314b1d64e1 --- /dev/null +++ b/validation-test/Driver/Dependencies/Inputs/rdar25405605/helper-2.swift @@ -0,0 +1,14 @@ +enum Foo { + case one + case two + case three +} + +func doSomething(_ value: Foo) { + switch value { + case .one: + print("Hello") + case .two: + print("Goodbye") + } +} diff --git a/validation-test/Driver/Dependencies/Inputs/rdar25405605/helper-3.swift b/validation-test/Driver/Dependencies/Inputs/rdar25405605/helper-3.swift new file mode 100644 index 0000000000000..89c1f94a47824 --- /dev/null +++ b/validation-test/Driver/Dependencies/Inputs/rdar25405605/helper-3.swift @@ -0,0 +1,15 @@ +enum Foo { + case one + case two + case three +} + +func doSomething(_ value: Foo) { + switch value { + case .one: + print("Hello") + case .two: + print("Goodbye") + case .three: break + } +} diff --git a/validation-test/Driver/Dependencies/Inputs/rdar25405605/output.json b/validation-test/Driver/Dependencies/Inputs/rdar25405605/output.json new file mode 100644 index 0000000000000..7971d0ca6d0b4 --- /dev/null +++ b/validation-test/Driver/Dependencies/Inputs/rdar25405605/output.json @@ -0,0 +1,13 @@ +{ + "./helper.swift": { + "object": "./helper.o", + "swift-dependencies": "./helper.swiftdeps", + }, + "./main.swift": { + "object": "./main.o", + "swift-dependencies": "./main.swiftdeps", + }, + "": { + "swift-dependencies": "./main~buildrecord.swiftdeps" + } +} diff --git a/validation-test/Driver/Dependencies/rdar25405605.swift b/validation-test/Driver/Dependencies/rdar25405605.swift new file mode 100644 index 0000000000000..7d29f7bfa8399 --- /dev/null +++ b/validation-test/Driver/Dependencies/rdar25405605.swift @@ -0,0 +1,81 @@ +// RUN: rm -rf %t && mkdir %t + +// RUN: cp %s %t/main.swift +// RUN: cp %S/Inputs/rdar25405605/helper-1.swift %t/helper.swift +// RUN: touch -t 201401240005 %t/*.swift + +// RUN: cd %t && %target-build-swift -c -incremental -output-file-map %S/Inputs/rdar25405605/output.json -parse-as-library ./main.swift ./helper.swift -parseable-output -j1 -module-name main 2>&1 | FileCheck -check-prefix=CHECK-1 %s + +// CHECK-1-NOT: warning +// CHECK-1: {{^{$}} +// CHECK-1: "kind": "began" +// CHECK-1: "name": "compile" +// CHECK-1: ".\/main.swift" +// CHECK-1: {{^}$}} + +// CHECK-1: {{^{$}} +// CHECK-1: "kind": "began" +// CHECK-1: "name": "compile" +// CHECK-1: ".\/helper.swift" +// CHECK-1: {{^}$}} + +// RUN: ls %t/ | FileCheck -check-prefix=CHECK-LS %s + +// CHECK-LS-DAG: main.o +// CHECK-LS-DAG: helper.o + +// RUN: cd %t && %target-build-swift -c -incremental -output-file-map %S/Inputs/rdar25405605/output.json -parse-as-library ./main.swift ./helper.swift -parseable-output -j1 -module-name main 2>&1 | FileCheck -check-prefix=CHECK-1-SKIPPED %s + +// CHECK-1-SKIPPED-NOT: warning +// CHECK-1-SKIPPED: {{^{$}} +// CHECK-1-SKIPPED: "kind": "skipped" +// CHECK-1-SKIPPED: "name": "compile" +// CHECK-1-SKIPPED: ".\/main.swift" +// CHECK-1-SKIPPED: {{^}$}} + +// CHECK-1-SKIPPED: {{^{$}} +// CHECK-1-SKIPPED: "kind": "skipped" +// CHECK-1-SKIPPED: "name": "compile" +// CHECK-1-SKIPPED: ".\/helper.swift" +// CHECK-1-SKIPPED: {{^}$}} + +// RUN: cp %S/Inputs/rdar25405605/helper-2.swift %t/helper.swift +// RUN: touch -t 201401240006 %t/helper.swift +// RUN: cd %t && not %target-build-swift -c -incremental -output-file-map %S/Inputs/rdar25405605/output.json -parse-as-library ./main.swift ./helper.swift -parseable-output -j1 -module-name main 2>&1 | FileCheck -check-prefix=CHECK-2 %s + +// CHECK-2-NOT: warning +// CHECK-2: {{^{$}} +// CHECK-2: "kind": "began" +// CHECK-2: "name": "compile" +// CHECK-2: ".\/helper.swift" +// CHECK-2: {{^}$}} + +// CHECK-2: {{^{$}} +// CHECK-2: "kind": "skipped" +// CHECK-2: "name": "compile" +// CHECK-2: ".\/main.swift" +// CHECK-2: {{^}$}} + +// RUN: cp %S/Inputs/rdar25405605/helper-3.swift %t/helper.swift +// RUN: touch -t 201401240007 %t/helper.swift +// RUN: cd %t && not %target-build-swift -c -incremental -output-file-map %S/Inputs/rdar25405605/output.json -parse-as-library ./main.swift ./helper.swift -parseable-output -j1 -module-name main 2>&1 | FileCheck -check-prefix=CHECK-3 %s + +// CHECK-3-NOT: warning +// CHECK-3: {{^{$}} +// CHECK-3: "kind": "began" +// CHECK-3: "name": "compile" +// CHECK-3: ".\/helper.swift" +// CHECK-3: {{^}$}} + +// CHECK-3: {{^{$}} +// CHECK-3: "kind": "began" +// CHECK-3: "name": "compile" +// CHECK-3: ".\/main.swift" +// CHECK-3: {{^}$}} + +func foo(_ value: Foo) -> Bool { + switch value { + case .one: return true + case .two: return false + } +} diff --git a/validation-test/stdlib/CoreGraphics-execute.swift b/validation-test/stdlib/CoreGraphics-execute.swift new file mode 100644 index 0000000000000..f4602c4f92f09 --- /dev/null +++ b/validation-test/stdlib/CoreGraphics-execute.swift @@ -0,0 +1,52 @@ +// RUN: %target-run-simple-swift +// REQUIRES: executable_test + +// REQUIRES: objc_interop +// REQUIRES: OS=macosx +import CoreGraphics +import StdlibUnittest + +//===----------------------------------------------------------------------===// +// CGAffineTransform +//===----------------------------------------------------------------------===// + +// Equatable conformance via CGAffineTransformEqualToTransform +let bourne = CGAffineTransform(a: 1, b: 0, c: 0, d: 1, tx: 0, ty: 0) +expectEqual(bourne, CGAffineTransform.identity) + +//===----------------------------------------------------------------------===// +// CGColor +//===----------------------------------------------------------------------===// + +// CGColor.components +let red = CGColor(red: 1, green: 0, blue: 0, alpha: 1) +let components = red.components! +expectEqual(components.count, 4) +expectEqual(components[0], 1) +expectEqual(components[1], 0) +expectEqual(components[2], 0) +expectEqual(components[3], 1) + +// CGColor Equatable conformance via CGColorEqualToColor +let 赤 = CGColor(red: 1, green: 0, blue: 0, alpha: 1) +expectEqual(red, 赤) + +//===----------------------------------------------------------------------===// +// CGGeometry +//===----------------------------------------------------------------------===// + +// other tests elsewhere for basics, only the new stuff here +let point = CGPoint(x: 1, y: 2) +let pDict = point.dictionaryRepresentation +let newPoint = CGPoint(dictionaryRepresentation: pDict) +expectOptionalEqual(point, newPoint) + +let size = CGSize(width: 3, height: 4) +let sDict = size.dictionaryRepresentation +let newSize = CGSize(dictionaryRepresentation: sDict) +expectOptionalEqual(size, newSize) + +let rect = CGRect(origin: point, size: size) +let rDict = rect.dictionaryRepresentation +let newRect = CGRect(dictionaryRepresentation: rDict) +expectOptionalEqual(rect, newRect) diff --git a/validation-test/stdlib/CoreGraphics-verifyOnly.swift b/validation-test/stdlib/CoreGraphics-verifyOnly.swift new file mode 100644 index 0000000000000..da494ddddb0f9 --- /dev/null +++ b/validation-test/stdlib/CoreGraphics-verifyOnly.swift @@ -0,0 +1,126 @@ +// RUN: %target-parse-verify-swift +// REQUIRES: objc_interop + +import CoreGraphics + +//===----------------------------------------------------------------------===// +// CGColorSpace +//===----------------------------------------------------------------------===// + +// CGColorSpace.colorTable +// TODO: has memory issues as a runtime test, so make it verify-only for now +let table: [UInt8] = [0,0,0, 255,0,0, 0,0,255, 0,255,0, + 255,255,0, 255,0,255, 0,255,255, 255,255,255] +let space = CGColorSpace(indexedBaseSpace: CGColorSpaceCreateDeviceRGB(), + last: table.count - 1, colorTable: table)! +// expectOptionalEqual(table, space.colorTable) + +//===----------------------------------------------------------------------===// +// CGContext +//===----------------------------------------------------------------------===// + +func testCGContext(context: CGContext, image: CGImage, glyph: CGGlyph) { + + context.setLineDash(phase: 0.5, lengths: [0.1, 0.2]) + + context.move(to: CGPoint.zero) + + context.addLine(to: CGPoint(x: 0.5, y: 0.5)) + + context.addCurve(to: CGPoint(x: 1, y: 1), control1: CGPoint(x: 1, y: 0), control2: CGPoint(x: 0, y: 1)) + + context.addQuadCurve(to: CGPoint(x: 0.5, y: 0.5), control: CGPoint(x: 0.5, y: 0)) + + context.addRects([CGRect(x: 0, y: 0, width: 100, height: 100)]) + + context.addLines(between: [CGPoint(x: 0.5, y: 0.5)]) + + context.addArc(center: CGPoint(x: 0.5, y: 0.5), radius: 1, startAngle: 0, endAngle: .pi, clockwise: false) + + context.addArc(tangent1End: CGPoint(x: 1, y: 1), tangent2End: CGPoint(x: 0.5, y: 0.5), radius: 0.5) + + context.fill([CGRect(x: 0, y: 0, width: 100, height: 100)]) + + context.fillPath() + context.fillPath(using: .evenOdd) + + context.strokeLineSegments(between: [CGPoint(x: 0.5, y: 0.5), CGPoint(x: 0, y: 0.5)]) + + context.clip(to: [CGRect(x: 0, y: 0, width: 100, height: 100)]) + + context.clip() + context.clip(using: .evenOdd) + + context.draw(image, in: CGRect(x: 0, y: 0, width: 100, height: 100), byTiling: true) + + print(context.textPosition) + + context.showGlyphs([glyph], at: [CGPoint(x: 0.5, y: 0.5)]) + +} + +//===----------------------------------------------------------------------===// +// CGDirectDisplay +//===----------------------------------------------------------------------===// + +#if os(macOS) +let (dx, dy) = CGGetLastMouseDelta() +#endif + +//===----------------------------------------------------------------------===// +// CGImage +//===----------------------------------------------------------------------===// + +func testCGImage(image: CGImage) -> CGImage? { + return image.copy(maskingColorComponents: [1, 0, 0]) +} + +//===----------------------------------------------------------------------===// +// CGLayer +//===----------------------------------------------------------------------===// + +func testDrawLayer(in context: CGContext) { + let layer = CGLayer(context, size: CGSize(width: 512, height: 384), + auxiliaryInfo: nil)! + context.draw(layer, in: CGRect(origin: .zero, size: layer.size)) + context.draw(layer, at: CGPoint(x: 20, y: 20)) +} + +func testCGPath(path: CGPath) { + + let dashed = path.copy(dashingWithPhase: 1, lengths: [0.2, 0.3, 0.5]) + + let stroked = path.copy(strokingWithWidth: 1, lineCap: .butt, + lineJoin: .miter, miterLimit: 0.1) + + let mutable = stroked.mutableCopy()! + + // test inferred transform parameter for all below + print(path.contains(CGPoint(x: 0.5, y: 0.5))) + print(path.contains(CGPoint(x: 0.5, y: 0.5), using: .evenOdd)) + + mutable.move(to: .zero) + + mutable.addLine(to: CGPoint(x: 0.5, y: 0.5)) + + mutable.addCurve(to: CGPoint(x: 1, y: 1), control1: CGPoint(x: 1, y: 0), control2: CGPoint(x: 0, y: 1)) + + mutable.addQuadCurve(to: CGPoint(x: 0.5, y: 0.5), control: CGPoint(x: 0.5, y: 0)) + + mutable.addRect(CGRect(x: 0, y: 0, width: 10, height: 10)) + mutable.addRects([CGRect(x: 0, y: 0, width: 100, height: 100)]) + + mutable.addLines(between: [CGPoint(x: 0.5, y: 0.5)]) + + mutable.addEllipse(in: CGRect(x: 0, y: 0, width: 50, height: 70)) + + mutable.addArc(center: CGPoint(x: 0.5, y: 0.5), radius: 1, startAngle: 0, endAngle: .pi, clockwise: false) + + mutable.addArc(tangent1End: CGPoint(x: 1, y: 1), tangent2End: CGPoint(x: 0.5, y: 0.5), radius: 0.5) + + mutable.addRelativeArc(center: CGPoint(x: 1, y: 1), radius: 0.5, + startAngle: .pi, delta: .pi/2) + + mutable.addPath(dashed) + +} diff --git a/validation-test/stdlib/FixedPoint.swift.gyb b/validation-test/stdlib/FixedPoint.swift.gyb index 731480479d9f2..c6c2801887959 100644 --- a/validation-test/stdlib/FixedPoint.swift.gyb +++ b/validation-test/stdlib/FixedPoint.swift.gyb @@ -9,6 +9,7 @@ var FixedPoint = TestSuite("FixedPoint") %{ import gyb +from SwiftIntTypes import all_integer_types test_bit_patterns = [ 0x0000000000000000, @@ -61,6 +62,32 @@ def get_fixed_point_hash(bit_pattern, src_bits, word_bits): }% +//===----------------------------------------------------------------------===// +// 'Int.Stride' type +//===----------------------------------------------------------------------===// + +FixedPoint.test("Integers.Stride") { +#if arch(i386) || arch(arm) + +% for self_ty in all_integer_types(32): +% Self = self_ty.stdlib_name + expectEqualType(Int.self, ${Self}.Stride.self) +% end + +#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x) + +% for self_ty in all_integer_types(64): +% Self = self_ty.stdlib_name + expectEqualType(Int.self, ${Self}.Stride.self) +% end + +#else + +_UnimplementedError() + +#endif +} + //===----------------------------------------------------------------------===// // 'Int(truncatingBitPattern:)' initializer //===----------------------------------------------------------------------===// diff --git a/validation-test/stdlib/GameplayKit.swift b/validation-test/stdlib/GameplayKit.swift index e2cfebb6bfe8f..57c6897ad81be 100644 --- a/validation-test/stdlib/GameplayKit.swift +++ b/validation-test/stdlib/GameplayKit.swift @@ -14,6 +14,45 @@ import GameplayKit var GamePlayKitTests = TestSuite("GameplayKit") +if #available(OSX 10.12, iOS 10.0, tvOS 10.0, *) { + + GamePlayKitTests.test("GKPath_float2") { + let vec: [float2] = [float2(3.0), float2(4.0)] + let path = GKPath(points: vec, radius: Float(30), cyclical: true) + expectEqual(path.numPoints, 2) + expectEqual(path.radius, Float(30)) + expectEqual(path.isCyclical, true) + } + GamePlayKitTests.test("GKPath_float3") { + let vec: [float3] = [float3(3.0), float3(4.0)] + let path = GKPath(points: vec, radius: Float(30), cyclical: true) + expectEqual(path.numPoints, 2) + expectEqual(path.radius, Float(30)) + expectEqual(path.isCyclical, true) + } + GamePlayKitTests.test("GKPolygonObstacle") { + let vec = [float2(3.0, 3.0), float2(3.0, -3.0), float2(-3.0, 3.0), float2(-3.0, -3.0)] + let obstacle = GKPolygonObstacle(points: vec) + expectEqual(obstacle.vertexCount, 4) + } + GamePlayKitTests.test("GKEntity") { + @objc(MovementComponent) + class MovementComponent: GKComponent { + override func update(deltaTime seconds: TimeInterval) {} + override func didAddToEntity() {} + override func willRemoveFromEntity() {} + } + let comp = MovementComponent() + let entity = GKEntity() + entity.addComponent(comp) + expectEqual(entity.components.count, 1) + let grabbedComp = entity.component(ofType: MovementComponent.self) + expectEqual(grabbedComp, comp) + entity.removeComponent(ofType: MovementComponent.self) + expectEqual(entity.components.count, 0) + } +} + if #available(OSX 10.11, iOS 9.0, tvOS 9.0, *) { class TestComponent : GKComponent {} @@ -22,15 +61,15 @@ class OtherTestComponent : GKComponent {} class TestState1 : GKState {} class TestState2 : GKState {} -GamePlayKitTests.test("GKEntity.componentForClass()") { +GamePlayKitTests.test("GKEntity.component(ofType)") { let entity = GKEntity() entity.addComponent(TestComponent()) do { var componentForTestComponent = - entity.componentForClass(TestComponent.self) + entity.component(ofType: TestComponent.self) var componentForOtherTestComponent_nil = - entity.componentForClass(OtherTestComponent.self) + entity.component(ofType: OtherTestComponent.self) expectNotEmpty(componentForTestComponent) expectType(Optional.self, &componentForTestComponent) @@ -38,14 +77,14 @@ GamePlayKitTests.test("GKEntity.componentForClass()") { expectEmpty(componentForOtherTestComponent_nil) } - entity.removeComponent(for: TestComponent.self) + entity.removeComponent(ofType: TestComponent.self) entity.addComponent(OtherTestComponent()) do { var componentForOtherTestComponent = - entity.componentForClass(OtherTestComponent.self) + entity.component(ofType: OtherTestComponent.self) var componentForTestComponent_nil = - entity.componentForClass(TestComponent.self) + entity.component(ofType: TestComponent.self) expectNotEmpty(componentForOtherTestComponent) expectType(Optional.self, &componentForOtherTestComponent) @@ -54,16 +93,16 @@ GamePlayKitTests.test("GKEntity.componentForClass()") { } } -GamePlayKitTests.test("GKStateMachine.stateForClass()") { +GamePlayKitTests.test("GKStateMachine.state(forClass:)") { do { // Construct a state machine with a custom subclass as the only state. let stateMachine = GKStateMachine( states: [TestState1()]) var stateForTestState1 = - stateMachine.stateForClass(TestState1.self) + stateMachine.state(forClass: TestState1.self) var stateForTestState2_nil = - stateMachine.stateForClass(TestState2.self) + stateMachine.state(forClass: TestState2.self) expectNotEmpty(stateForTestState1) expectType(Optional.self, &stateForTestState1) @@ -77,9 +116,9 @@ GamePlayKitTests.test("GKStateMachine.stateForClass()") { states: [TestState2()]) var stateForTestState2 = - stateMachine.stateForClass(TestState2.self) + stateMachine.state(forClass: TestState2.self) var stateForTestState1_nil = - stateMachine.stateForClass(TestState1.self) + stateMachine.state(forClass: TestState1.self) expectNotEmpty(stateForTestState2) expectType(Optional.self, &stateForTestState2) diff --git a/validation-test/stdlib/NewArray.swift.gyb b/validation-test/stdlib/NewArray.swift.gyb index 283fb6f48f793..1e3a19a592718 100644 --- a/validation-test/stdlib/NewArray.swift.gyb +++ b/validation-test/stdlib/NewArray.swift.gyb @@ -472,7 +472,7 @@ class Rdar16914909 : NSObject { var basicColorSet = [OSColor]() func doColorStuff() { - basicColorSet.append(OSColor.lightGray()) + basicColorSet.append(OSColor.lightGray) print("appended") } } diff --git a/validation-test/stdlib/SceneKit.swift b/validation-test/stdlib/SceneKit.swift index f828482f728f7..2de7f60f90251 100644 --- a/validation-test/stdlib/SceneKit.swift +++ b/validation-test/stdlib/SceneKit.swift @@ -136,7 +136,7 @@ if #available(iOS 8.0, *) { let source = SCNGeometrySource(vertices: [SCNVector3(1, 2, 3), SCNVector3(4, 5, 6)]) - expectEqual(source.semantic, SCNGeometrySourceSemanticVertex) + expectEqual(source.semantic, SCNGeometrySource.Semantic.vertex) expectEqual(source.vectorCount, 2) expectEqual(source.componentsPerVector, 3) @@ -150,7 +150,7 @@ if #available(iOS 8.0, *) { let source = SCNGeometrySource(normals: [SCNVector3(1, 2, 3), SCNVector3(4, 5, 6)]) - expectEqual(source.semantic, SCNGeometrySourceSemanticNormal) + expectEqual(source.semantic, SCNGeometrySource.Semantic.normal) expectEqual(source.vectorCount, 2) expectEqual(source.componentsPerVector, 3) @@ -164,7 +164,7 @@ if #available(iOS 8.0, *) { let source = SCNGeometrySource(textureCoordinates: [CGPoint(x: 1, y: 2), CGPoint(x: 4, y: 5)]) - expectEqual(source.semantic, SCNGeometrySourceSemanticTexcoord) + expectEqual(source.semantic, SCNGeometrySource.Semantic.texcoord) expectEqual(source.vectorCount, 2) expectEqual(source.componentsPerVector, 2) @@ -346,7 +346,7 @@ if #available(iOS 8.0, *) { let sceneData = sceneDescription.data( using: .utf8, allowLossyConversion: true)! - let sceneSource = SCNSceneSource(data: sceneData as Data, options: nil)! + let sceneSource = SCNSceneSource(data: sceneData as Data, options: [:])! do { var unarchivedPlaneGeometry = diff --git a/validation-test/stdlib/SpriteKit.swift b/validation-test/stdlib/SpriteKit.swift new file mode 100644 index 0000000000000..fe1378963fa00 --- /dev/null +++ b/validation-test/stdlib/SpriteKit.swift @@ -0,0 +1,94 @@ +// RUN: %target-run-simple-swift +// REQUIRES: executable_test + +// REQUIRES: objc_interop + +import StdlibUnittest + +import Foundation +import SpriteKit + +var SpriteKitTests = TestSuite("SpriteKit") + +// Check that the subscript is there. +@available(OSX,introduced: 10.10) +@available(iOS,introduced: 8.0) +@available(tvOS,introduced: 8.0) +@available(watchOS,introduced: 2.0) +func testSubscript(_ node: SKNode) { + var result = node["me"] + expectType(Array.self, &result) +} + +SpriteKitTests.test("SKColor/TypeEquivalence") { + // SKColor is NSColor on OS X and UIColor on iOS. +#if os(OSX) + expectEqualType(NSColor.self, SKColor.self) +#elseif os(iOS) || os(tvOS) || os(watchOS) + expectEqualType(UIColor.self, SKColor.self) +#else + _UnknownOSError() +#endif +} + +SpriteKitTests.test("getRed(_:green:blue:alpha:)") { + var r: CGFloat = 0.0 + var g: CGFloat = 0.0 + var b: CGFloat = 0.0 + var a: CGFloat = 0.0 + let color = SKColor.red + color.getRed(&r, green: &g, blue: &b, alpha: &a) + expectEqual(1.0, r) + expectEqual(0.0, g) + expectEqual(0.0, b) + expectEqual(1.0, a) +} + +if #available(OSX 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *) { + SpriteKitTests.test("SKNode.setValue(_:forAttribute:)") { + let node = SKNode() + let attrVal = SKAttributeValue(float: 2.0) + node.setValue(attrVal, forAttribute: "test") + expectEqual(node.attributeValues["test"], attrVal) + } + + SpriteKitTests.test("SKWarpGeometryGrid/1") { + var warpGrid = SKWarpGeometryGrid(columns: 1, rows: 1) + expectEqual(warpGrid.numberOfColumns, 1) + + expectEqual(warpGrid.sourcePosition(at: 0).x, 0.0) + warpGrid = warpGrid.replacingBySourcePositions(positions: [float2(1.0), float2(2.0), float2(3.0), float2(4.0)]) + expectEqual(warpGrid.sourcePosition(at: 0).x, 1.0) + + expectEqual(warpGrid.destPosition(at: 0).x, 0.0) + warpGrid = warpGrid.replacingByDestinationPositions(positions: [float2(1.0), float2(2.0), float2(3.0), float2(4.0)]) + expectEqual(warpGrid.destPosition(at: 0).x, 1.0) + + warpGrid = SKWarpGeometryGrid(columns: 1, rows: 1, destinationPositions: [float2(1.0), float2(2.0), float2(3.0), float2(4.0)]) + expectEqual(warpGrid.destPosition(at: 0).x, 1.0) + expectEqual(warpGrid.sourcePosition(at: 0).x, 0.0) + + warpGrid = SKWarpGeometryGrid(columns: 1, rows: 1, sourcePositions: [float2(1.0), float2(2.0), float2(3.0), float2(4.0)]) + expectEqual(warpGrid.destPosition(at: 0).x, 0.0) + expectEqual(warpGrid.sourcePosition(at: 0).x, 1.0) + + warpGrid = SKWarpGeometryGrid(columns: 1, rows: 1, sourcePositions: [float2(2.0), float2(1.0), float2(3.0), float2(4.0)], destinationPositions: [float2(1.0), float2(2.0), float2(3.0), float2(4.0)]) + expectEqual(warpGrid.destPosition(at: 0).x, 1.0) + expectEqual(warpGrid.sourcePosition(at: 0).x, 2.0) + } + + SpriteKitTests.test("SKWarpGeometryGrid/2") { + var warpGrid = SKWarpGeometryGrid(columns: 3, rows: 4) + expectEqual(warpGrid.numberOfColumns, 3) + + expectEqual(warpGrid.sourcePosition(at: 0).x, 0.0) + warpGrid = warpGrid.replacingBySourcePositions(positions: [float2(30.0)]) + expectEqual(warpGrid.sourcePosition(at: 0).x, 30.0) + + expectEqual(warpGrid.destPosition(at: 0).x, 0.0) + warpGrid = warpGrid.replacingByDestinationPositions(positions: [float2(30.0)]) + expectEqual(warpGrid.destPosition(at: 0).x, 30.0) + } +} + +runAllTests()