Skip to content

Instantly share code, notes, and snippets.

View niw's full-sized avatar
🐱
Meow

Yoshimasa Niwa niw

🐱
Meow
View GitHub Profile
@niw
niw / example.swift
Created April 4, 2020 00:47
macOS 10.15.4 Catalyst erases the underline for input method marked text if content attributed text has `.underlineStyle`.
let textView = UITextView(frame: view.bounds)
textView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
let text = NSMutableAttributedString(string: "test")
text.addAttributes([
.font: UIFont.systemFont(ofSize: 20.0),
.foregroundColor: UIColor.label,
.underlineStyle: 0
], range: NSRange(location: 0, length: text.length))
@niw
niw / do_not_duplicate_InitExistentialAddrInst.patch
Created April 3, 2020 17:51
I have no idea what I am doing.
diff --git a/lib/SIL/IR/SILInstruction.cpp b/lib/SIL/IR/SILInstruction.cpp
index b1e14d28d4..50d6016d68 100644
--- a/lib/SIL/IR/SILInstruction.cpp
+++ b/lib/SIL/IR/SILInstruction.cpp
@@ -1215,6 +1215,9 @@ bool SILInstruction::isTriviallyDuplicatable() const {
// If you add more cases here, you should also update SILLoop:canDuplicate.
+ if (isa<InitExistentialAddrInst>(this))
+ return false;
@niw
niw / main.swift
Last active April 3, 2020 17:52
I found a SILOptimizer problem.
// `swiftc -Osize main.swift` then crash.
// Apple Swift version 5.2 (swiftlang-1103.0.32.1 clang-1103.0.32.29).
struct S {
}
struct T {
let s: S
}
@niw
niw / README.md
Last active March 23, 2020 21:31
How to embed user-specific dynamic variables updated every build in `Info.plist`

How to embed user-specific dynamic variables updated every build in Info.plist

Info.plist can contain many dynamic variables that you can specify in Xcode configuration file by using Build Settings parameters.

However, Xcode configuration is a static environment and you can NOT inject any dynamic variables except Build Settings parameters.

One of solutions is using Pre-actions in Build scheme to update Xcode configuration file dynamically, however, it creates invisible dependency between scheme configuration and each project configuration.

Use Info.plist preprocessor

@niw
niw / a.swift
Created February 25, 2020 22:53
Combine can't be weakly linked on Xcode 11.3
// Run `swiftc -target x86_64-apple-macosx10.14 a.swift && nm -mg ./a`
// We will see non-weak symbol from Combine:
// `(extension in Combine):Combine.Subject< where A.Output == ()>.send() -> ()`
import Combine
@available(macOS 10.15, *)
func test() {
let s = PassthroughSubject<Void, Never>()
s.send()
@niw
niw / non_weak_references.txt
Created February 25, 2020 22:31
Some symbols are not weak
(undefined) external _$s7Combine14AnyCancellableC5store2inyShyACGz_tF (from Combine)
(undefined) external _$s7Combine7SubjectPAAyt6OutputRtzrlE4sendyyF (from Combine)
(undefined) external _$s7SwiftUI4ViewPAAE010navigationC5StyleyQrqd__AA010NavigationcE0Rd__lFQOMQ (from SwiftUI)
(undefined) external _$s7SwiftUI4ViewPAAE18navigationBarItems8trailingQrqd___tAaBRd__lFQOMQ (from SwiftUI)
(undefined) external _$s7SwiftUI4ViewPAAE18navigationBarTitle_11displayModeQrAA4TextV_AA010NavigationE4ItemV0f7DisplayH0OtFQOMQ (from SwiftUI)
@niw
niw / FlipFlop.scala
Created February 14, 2020 07:08
Learning Chisel: Flip Flop
import chisel3._
class SRLatch extends Module {
val io = IO(new Bundle {
val set = Input(Bool())
val reset = Input(Bool())
val q = Output(Bool())
val notQ = Output(Bool())
})
@niw
niw / AddrLED.scala
Last active February 7, 2020 08:27
Learning Chisel: n-bit full addr
import chisel3._
import chisel3.util._
class HalfAddr extends Module {
val io = IO(new Bundle {
val inA = Input(UInt(1.W))
val inB = Input(UInt(1.W))
val outSum = Output(UInt(1.W))
val outCarry = Output(UInt(1.W))
@niw
niw / AddrLED.scala
Last active February 7, 2020 08:10
Learning Chisel: 2-bit full addr
import chisel3._
import chisel3.util._
class HalfAddr extends Module {
val io = IO(new Bundle {
val inA = Input(UInt(1.W))
val inB = Input(UInt(1.W))
val outSum = Output(UInt(1.W))
val outCarry = Output(UInt(1.W))
@niw
niw / SevenSegLED.scala
Last active February 6, 2020 20:03
Learning Chisel: Mux to decode unsigned integer to 7-seg LED
import chisel3._
import chisel3.util._
class SevenSegLED extends Module {
val io = IO(new Bundle {
val input = Input(UInt(4.W))
val output = Output(UInt(8.W))
})
io.output := MuxCase(