-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1032 from hylo-lang/globals-in-generics
Fix monomorphization of constant strings in generic functions
- Loading branch information
Showing
7 changed files
with
82 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import Core | ||
import Foundation | ||
|
||
/// Creates a pointer to a constant string allocated statically. | ||
public struct ConstantString: Instruction { | ||
|
||
/// The value of the string, encoded in UTF-8. | ||
public let value: Data | ||
|
||
/// The site of the code corresponding to that instruction. | ||
public let site: SourceRange | ||
|
||
/// Creates an instance with the given properties. | ||
fileprivate init(value: Data, site: SourceRange) { | ||
self.value = value | ||
self.site = site | ||
} | ||
|
||
public var result: IR.`Type`? { | ||
.object(BuiltinType.ptr) | ||
} | ||
|
||
public var operands: [Operand] { [] } | ||
|
||
public mutating func replaceOperand(at i: Int, with new: Operand) { | ||
preconditionFailure() | ||
} | ||
|
||
} | ||
|
||
extension ConstantString: CustomStringConvertible { | ||
|
||
public var description: String { | ||
"constant_string \"\(value)\"" | ||
} | ||
|
||
} | ||
|
||
extension Module { | ||
|
||
/// Creates a `constant_string` anchored at `site` that returns a pointer to a statically | ||
/// allocated string with given `value`, encoded in UTF8. | ||
func makeConstantString(utf8 value: Data, at site: SourceRange) -> ConstantString { | ||
.init(value: value, site: site) | ||
} | ||
|
||
} |