Skip to content

[SR-1647] Compiler hangs on large array of NSLayoutConstraints, with a type annotation #44256

Open
@swift-ci

Description

@swift-ci
Previous ID SR-1647
Radar None
Original Reporter Nowak (JIRA User)
Type Bug
Environment

Xcode 7.3.1, Xcode 8.0 (8A218a)
iOS 9.3, iOS 10

Additional Detail from JIRA
Votes 5
Component/s Compiler
Labels Bug, 2.2Regression, Performance, TypeChecker
Assignee None
Priority Medium

md5: 6e1cac7c3070003bafb401696215795b

Issue Description:

I have an project without storyboard.
All Compounds are arrenged by constraints.

On Swift 1 I have set all constraints in one big array an set it, with one addConstraints() call

On Swift 2.2 the Compiler will hang and was killed after 8 hours without any useful error message

As workaround a have found, that I need to set the Constraints on

Here is the function which let the compiler hangs:

func setConstraints()
    {
        
        var constraints:[NSLayoutConstraint] = [
            
            
            NSLayoutConstraint(item: positiveLabel,attribute: NSLayoutAttribute.Top,relatedBy: NSLayoutRelation.Equal,toItem: view,attribute: NSLayoutAttribute.Top,multiplier: 1,constant: 0),
            
            NSLayoutConstraint(item:positiveLabel,attribute: NSLayoutAttribute.Left,relatedBy: NSLayoutRelation.Equal,toItem: view,attribute: NSLayoutAttribute.Left,multiplier: 1,constant: 0),
            
            NSLayoutConstraint(item:positiveLabel,attribute: NSLayoutAttribute.Width,relatedBy: NSLayoutRelation.Equal,toItem: nil,attribute: NSLayoutAttribute.NotAnAttribute,multiplier: 1,constant: 50),
            /*
            ]
        view.addConstraints(constraints)
        constraints = [
 */
            NSLayoutConstraint(item: positiveBox,attribute: NSLayoutAttribute.CenterY,relatedBy: NSLayoutRelation.Equal,toItem: positiveLabel,attribute: NSLayoutAttribute.CenterY,multiplier: 1,constant: 0),
            
            NSLayoutConstraint(item:positiveBox,attribute: NSLayoutAttribute.Left,relatedBy: NSLayoutRelation.Equal,toItem: positiveLabel,attribute: NSLayoutAttribute.Right,multiplier: 1,constant: 10),
            
            NSLayoutConstraint(item:positiveBox,attribute: NSLayoutAttribute.Height,relatedBy: NSLayoutRelation.Equal,toItem: positiveLabel,attribute: NSLayoutAttribute.Height,multiplier: 0.8,constant: 0),
            
            NSLayoutConstraint(item:positiveBox,attribute: NSLayoutAttribute.Width,relatedBy: NSLayoutRelation.Equal,toItem: positiveBox,attribute: NSLayoutAttribute.Height,multiplier: 1,constant: 0),
   /*
        ]
        view.addConstraints(constraints)
        
        
        constraints = [
     */
            NSLayoutConstraint(item:negativeLabel,attribute: NSLayoutAttribute.Top,relatedBy: NSLayoutRelation.Equal,toItem: positiveLabel,attribute: NSLayoutAttribute.Bottom,multiplier: 1,constant: 0),
            NSLayoutConstraint(item:negativeLabel,attribute: NSLayoutAttribute.Left,relatedBy: NSLayoutRelation.Equal,toItem: view,attribute: NSLayoutAttribute.Left,multiplier: 1,constant: 0),
            NSLayoutConstraint(item:negativeLabel,attribute: NSLayoutAttribute.Width,relatedBy: NSLayoutRelation.Equal,toItem: nil,attribute: NSLayoutAttribute.NotAnAttribute,multiplier: 1,constant: 50),
       /*
            ]
        view.addConstraints(constraints)
        constraints = [
 */
            NSLayoutConstraint(item:negativeBox,attribute: NSLayoutAttribute.CenterY,relatedBy: NSLayoutRelation.Equal,toItem: negativeLabel,attribute: NSLayoutAttribute.CenterY,multiplier: 1,constant: 0),
            NSLayoutConstraint(item:negativeBox,attribute: NSLayoutAttribute.Left,relatedBy: NSLayoutRelation.Equal,toItem: negativeLabel,attribute: NSLayoutAttribute.Right,multiplier: 1,constant: 10),
            NSLayoutConstraint(item:negativeBox,attribute: NSLayoutAttribute.Height,relatedBy: NSLayoutRelation.Equal,toItem: negativeLabel,attribute: NSLayoutAttribute.Height,multiplier: 0.8,constant: 0),
            NSLayoutConstraint(item:negativeBox,attribute: NSLayoutAttribute.Width,relatedBy: NSLayoutRelation.Equal,toItem: negativeBox,attribute: NSLayoutAttribute.Height,multiplier: 1,constant: 0),
   /*
        ]
        view.addConstraints(constraints)
        
        
        constraints = [
 */
            NSLayoutConstraint(item:neutralLabel,attribute: NSLayoutAttribute.Top,relatedBy: NSLayoutRelation.Equal,toItem: negativeLabel,attribute: NSLayoutAttribute.Bottom,multiplier: 1,constant: 0),
            NSLayoutConstraint(item:neutralLabel,attribute: NSLayoutAttribute.Left,relatedBy: NSLayoutRelation.Equal,toItem: view,attribute: NSLayoutAttribute.Left,multiplier: 1,constant: 0),
            NSLayoutConstraint(item:neutralLabel,attribute: NSLayoutAttribute.Width,relatedBy: NSLayoutRelation.Equal,toItem: nil,attribute: NSLayoutAttribute.NotAnAttribute,multiplier: 1,constant: 50),
   /*
            ]
        view.addConstraints(constraints)
        constraints = [
 */
            NSLayoutConstraint(item:neutralBox,attribute: NSLayoutAttribute.CenterY,relatedBy: NSLayoutRelation.Equal,toItem: neutralLabel,attribute: NSLayoutAttribute.CenterY,multiplier: 1,constant: 0),
            NSLayoutConstraint(item:neutralBox,attribute: NSLayoutAttribute.Left,relatedBy: NSLayoutRelation.Equal,toItem: neutralLabel,attribute: NSLayoutAttribute.Right,multiplier: 1,constant: 10),
            NSLayoutConstraint(item:neutralBox,attribute: NSLayoutAttribute.Height,relatedBy: NSLayoutRelation.Equal,toItem: neutralLabel,attribute: NSLayoutAttribute.Height,multiplier: 0.8,constant: 0),
            NSLayoutConstraint(item:neutralBox,attribute: NSLayoutAttribute.Width,relatedBy: NSLayoutRelation.Equal,toItem: neutralBox,attribute: NSLayoutAttribute.Height,multiplier: 1,constant: 0),
        ]
        view.addConstraints(constraints)


}

The short project to show the Error can be found here:

https://github.com/tn0/swiftError.git

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfperformanceregressionswift 2.2type checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions