mirror of
				https://github.com/golang/go.git
				synced 2025-10-26 06:14:13 +00:00 
			
		
		
		
	[dev.regabi] cmd/compile: remove refersToCommonName
After reorder3's simplification, the only remaining use of refersToCommonName is in oaslit, where the LHS expression is always a single name. We can replace the now overly-generalized refersToCommonName with a simple ir.Any traversal with ir.Uses. Passes toolstash -cmp. Change-Id: Ice3020cdbbf6083d52e07866a687580f4eb134b8 Reviewed-on: https://go-review.googlesource.com/c/go/+/280439 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
		
							parent
							
								
									c98548e110
								
							
						
					
					
						commit
						676d794b81
					
				
					 2 changed files with 2 additions and 50 deletions
				
			
		|  | @ -495,55 +495,6 @@ func readsMemory(n ir.Node) bool { | ||||||
| 	return true | 	return true | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // refersToCommonName reports whether any name |  | ||||||
| // appears in common between l and r. |  | ||||||
| // This is called from sinit.go. |  | ||||||
| func refersToCommonName(l ir.Node, r ir.Node) bool { |  | ||||||
| 	if l == nil || r == nil { |  | ||||||
| 		return false |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	// This could be written elegantly as a Find nested inside a Find: |  | ||||||
| 	// |  | ||||||
| 	//	found := ir.Find(l, func(l ir.Node) interface{} { |  | ||||||
| 	//		if l.Op() == ir.ONAME { |  | ||||||
| 	//			return ir.Find(r, func(r ir.Node) interface{} { |  | ||||||
| 	//				if r.Op() == ir.ONAME && l.Name() == r.Name() { |  | ||||||
| 	//					return r |  | ||||||
| 	//				} |  | ||||||
| 	//				return nil |  | ||||||
| 	//			}) |  | ||||||
| 	//		} |  | ||||||
| 	//		return nil |  | ||||||
| 	//	}) |  | ||||||
| 	//	return found != nil |  | ||||||
| 	// |  | ||||||
| 	// But that would allocate a new closure for the inner Find |  | ||||||
| 	// for each name found on the left side. |  | ||||||
| 	// It may not matter at all, but the below way of writing it |  | ||||||
| 	// only allocates two closures, not O(|L|) closures. |  | ||||||
| 
 |  | ||||||
| 	var doL, doR func(ir.Node) error |  | ||||||
| 	var targetL *ir.Name |  | ||||||
| 	doR = func(r ir.Node) error { |  | ||||||
| 		if r.Op() == ir.ONAME && r.Name() == targetL { |  | ||||||
| 			return stop |  | ||||||
| 		} |  | ||||||
| 		return ir.DoChildren(r, doR) |  | ||||||
| 	} |  | ||||||
| 	doL = func(l ir.Node) error { |  | ||||||
| 		if l.Op() == ir.ONAME { |  | ||||||
| 			l := l.(*ir.Name) |  | ||||||
| 			targetL = l.Name() |  | ||||||
| 			if doR(r) == stop { |  | ||||||
| 				return stop |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 		return ir.DoChildren(l, doL) |  | ||||||
| 	} |  | ||||||
| 	return doL(l) == stop |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| // expand append(l1, l2...) to | // expand append(l1, l2...) to | ||||||
| //   init { | //   init { | ||||||
| //     s := l1 | //     s := l1 | ||||||
|  |  | ||||||
|  | @ -629,6 +629,7 @@ func oaslit(n *ir.AssignStmt, init *ir.Nodes) bool { | ||||||
| 		// not a special composite literal assignment | 		// not a special composite literal assignment | ||||||
| 		return false | 		return false | ||||||
| 	} | 	} | ||||||
|  | 	x := n.X.(*ir.Name) | ||||||
| 	if !types.Identical(n.X.Type(), n.Y.Type()) { | 	if !types.Identical(n.X.Type(), n.Y.Type()) { | ||||||
| 		// not a special composite literal assignment | 		// not a special composite literal assignment | ||||||
| 		return false | 		return false | ||||||
|  | @ -640,7 +641,7 @@ func oaslit(n *ir.AssignStmt, init *ir.Nodes) bool { | ||||||
| 		return false | 		return false | ||||||
| 
 | 
 | ||||||
| 	case ir.OSTRUCTLIT, ir.OARRAYLIT, ir.OSLICELIT, ir.OMAPLIT: | 	case ir.OSTRUCTLIT, ir.OARRAYLIT, ir.OSLICELIT, ir.OMAPLIT: | ||||||
| 		if refersToCommonName(n.X, n.Y) { | 		if ir.Any(n.Y, func(y ir.Node) bool { return ir.Uses(y, x) }) { | ||||||
| 			// not a special composite literal assignment | 			// not a special composite literal assignment | ||||||
| 			return false | 			return false | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Matthew Dempsky
						Matthew Dempsky