profile
viewpoint
If you are wondering where the data of this site comes from, please visit https://api.github.com/users/Catfish-Man/events. GitMemory does not store any data, but only uses NGINX to cache data for a period of time. The idea behind GitMemory is simply to give users a better reading experience.

numist/Diffing-Explorations 9

A playground for diffing experiments along with the algorithms and data structures needed to support them

Catfish-Man/swift 1

The Swift Programming Language

Pull request review commentapple/swift-numerics

Right shift with rounding.

+//===--- Shift.swift ------------------------------------------*- swift -*-===//+//+// This source file is part of the Swift Numerics open source project+//+// Copyright (c) 2021 Apple Inc. and the Swift Numerics project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++extension BinaryInteger {+  /// self / 2^(count), rounded the results according to the specified rule.+  ///+  /// The default rounding rule is `.down`, which matches the behavior of+  /// the `>>` operator from the standard library.+  ///+  /// Some examples of different rounding rules:+  ///+  ///     // 3/2 is 1.5, which rounds (down by default) to 1.+  ///     3.shifted(right: 1)+  ///+  ///     // 1.5 rounds up to 2.+  ///     3.shifted(right: 1, rounding: .up)+  ///+  ///     // The two closest values are 1 and 2, 1 is returned because it+  ///     // is odd.+  ///     3.shifted(right: 1, rounding: .toOdd)+  ///+  ///     // 7/2^2 = 1.75, so the result is 1 with probability 1/4, and 2+  ///     // with probability 3/4.+  ///     7.shifted(right: 2, rounding: .stochastic)+  ///+  ///     // 4/2^2 = 4/4 = 1, exactly.+  ///     4.shifted(right: 2, rounding: .trap)+  ///+  ///     // 5/2 is 2.5, which is not exact, so this traps.+  ///     5.shifted(right: 1, rounding: .trap)+  @inlinable+  public func shifted<Count: BinaryInteger>(+    right count: Count,+    rounding rule: RoundingRule = .down

As someone who doesn't think about rounding very often I'm just going to assume that you've thought about this and there's an obvious default here, but I'm leaving this comment just on the tiny chance that on seeing it again you'll go "hm actually maybe they should always have to say what they want" :)

stephentyrone

comment created time in a day

PullRequestReviewEvent

Pull request review commentapple/swift-numerics

Right shift with rounding.

+//===--- Shift.swift ------------------------------------------*- swift -*-===//+//+// This source file is part of the Swift Numerics open source project+//+// Copyright (c) 2021 Apple Inc. and the Swift Numerics project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++extension BinaryInteger {+  /// self / 2^(count), rounded the results according to the specified rule.+  ///+  /// The default rounding rule is `.down`, which matches the behavior of+  /// the `>>` operator from the standard library.+  ///+  /// Some examples of different rounding rules:+  ///+  ///     // 3/2 is 1.5, which rounds (down by default) to 1.+  ///     3.shifted(right: 1)+  ///+  ///     // 1.5 rounds up to 2.+  ///     3.shifted(right: 1, rounding: .up)+  ///+  ///     // The two closest values are 1 and 2, 1 is returned because it+  ///     // is odd.+  ///     3.shifted(right: 1, rounding: .toOdd)+  ///+  ///     // 7/2^2 = 1.75, so the result is 1 with probability 1/4, and 2+  ///     // with probability 3/4.+  ///     7.shifted(right: 2, rounding: .stochastic)+  ///+  ///     // 4/2^2 = 4/4 = 1, exactly.+  ///     4.shifted(right: 2, rounding: .trap)+  ///+  ///     // 5/2 is 2.5, which is not exact, so this traps.+  ///     5.shifted(right: 1, rounding: .trap)+  @inlinable+  public func shifted<Count: BinaryInteger>(+    right count: Count,

I forget, what's the precedent here: do we usually include or omit "By"?

stephentyrone

comment created time in a day

Pull request review commentapple/swift-numerics

Right shift with rounding.

+//===--- Rounding.swift ---------------------------------------*- swift -*-===//+//+// This source file is part of the Swift Numerics open source project+//+// Copyright (c) 2021 Apple Inc. and the Swift Numerics project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++/// A rule that defines how to select one of the two representable results+/// closest to a given value.+public enum RoundingRule {

This feels a little inconsistent.

…, rounding: .down..., rounding: .stochastic should this be "stochastically"? ..., rounding: .trap in what circumstances does it trap? (I realize this is clear if you think about it for a moment, but maybe we can make it obvious at the point of use?)

Related, do we want rounding or do we want rounded? With the name shifted we're describing the resulting value, rather than the action, but with rounding we're describing the action.

stephentyrone

comment created time in a day

PullRequestReviewEvent

pull request commentapple/swift

Allow identification of OSLogMessage by a @_semantics attribute instead of just name

I'm not sure either tbh. It sounds interesting at least!

kubamracek

comment created time in 3 days

pull request commentapple/swift

Avoid protocol conformance lookups in more NSString bridging scenarios

@swift-ci please smoke test

Catfish-Man

comment created time in 6 days

push eventCatfish-Man/swift

David Smith

commit sha 3c8ab8a17c1aa956e38eac32584c5dfe2c273d4e

Something is really weird with this file, this shouldn't have worked at all I think?

view details

push time in 6 days

pull request commentapple/swift

Avoid protocol conformance lookups in more NSString bridging scenarios

Oh, it being incorrect probably has something to do with that, heh

Catfish-Man

comment created time in 6 days

pull request commentapple/swift

Avoid protocol conformance lookups in more NSString bridging scenarios

Huh. Interesting. I wonder why we're not seeing more of a win from the second change.

Catfish-Man

comment created time in 7 days

pull request commentapple/swift

Avoid protocol conformance lookups in more NSString bridging scenarios

@swift-ci please smoke test

Catfish-Man

comment created time in 7 days

pull request commentapple/swift

Avoid protocol conformance lookups in more NSString bridging scenarios

@swift-ci please smoke benchmark

Catfish-Man

comment created time in 7 days

push eventCatfish-Man/swift

David Smith

commit sha 87b2f64fb728f79e05339d7d4ff7e763cfddb4a6

Fix some stuff

view details

push time in 7 days

pull request commentapple/swift

Optimize NSString->AnyHashable and String->AnyHashable

@swift-ci please smoke benchmark

Catfish-Man

comment created time in 7 days

pull request commentapple/swift

Optimize NSString->AnyHashable and String->AnyHashable

@swift-ci please smoke test

Catfish-Man

comment created time in 7 days

push eventCatfish-Man/swift

David Smith

commit sha e887fd764d5de44741b4b44a5453444541443651

Use ObjCBridgeMemo for both directions

view details

push time in 7 days

pull request commentapple/swift

Optimize NSString->AnyHashable and String->AnyHashable

@swift-ci please benchmark

Catfish-Man

comment created time in 8 days

pull request commentapple/swift

Optimize NSString->AnyHashable and String->AnyHashable

@swift-ci please test

Catfish-Man

comment created time in 8 days

push eventCatfish-Man/swift

David Smith

commit sha 452da19ddb080a6b161d7736771aeaa479d47f94

Address review comments

view details

push time in 8 days

pull request commentapple/swift

Optimize NSString->AnyHashable and String->AnyHashable

@swift-ci please benchmark

Catfish-Man

comment created time in 8 days

pull request commentapple/swift

Optimize NSString->AnyHashable and String->AnyHashable

@swift-ci please test

Catfish-Man

comment created time in 8 days

PR opened apple/swift

Reviewers
Optimize NSString->AnyHashable and String->AnyHashable
+25 -6

0 comment

2 changed files

pr created time in 8 days

push eventCatfish-Man/swift

David Smith

commit sha 05d45fac75b066bf87896fd8ef0ab5b6ead84dda

Optimize NSString->AnyHashable and String->AnyHashable

view details

push time in 8 days

create barnchCatfish-Man/swift

branch : any-hashable-in-this-economy

created branch time in 8 days

Pull request review commentapple/swift

[irgen] Add a new experimental transform called StackSizeLimitTransform.

+//===--- StackSizeLimitTransform.cpp --------------------------------------===//+//+// This source file is part of the Swift.org open source project+//+// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors+//+//===----------------------------------------------------------------------===//+///+/// \file+///+/// This is a transform that ensures that swift allocations never blow out the+/// stack. We do this by limiting per function the amount of stack space+/// allocated and otherwise, heap allocate classes, values.+///+//===----------------------------------------------------------------------===//++#define DEBUG_TYPE "sil-irgen-stack-size-limit"++#include "ClassTypeInfo.h"+#include "IRGen.h"+#include "IRGenModule.h"+#include "swift/AST/IRGenOptions.h"+#include "swift/Basic/BlotMapVector.h"+#include "swift/Basic/FrozenMultiMap.h"+#include "swift/IRGen/IRGenSILPasses.h"+#include "swift/SIL/InstructionUtils.h"+#include "swift/SIL/SILBasicBlock.h"+#include "swift/SIL/SILBuilder.h"+#include "swift/SIL/SILInstruction.h"+#include "swift/SIL/SILInstructionWorklist.h"+#include "swift/SILOptimizer/PassManager/Passes.h"+#include "swift/SILOptimizer/PassManager/Transforms.h"+#include "swift/SILOptimizer/Utils/CanonicalizeInstruction.h"+#include "swift/SILOptimizer/Utils/InstOptUtils.h"+#include "llvm/IR/Constants.h"++using namespace swift;+using namespace swift::irgen;++//===----------------------------------------------------------------------===//+//                                  Utility+//===----------------------------------------------------------------------===//++/// Given an alloc_stack \p asi and the next element to process, convert asi's+/// users to use a new heap allocated box without invalidating next.+static SILBasicBlock::iterator+convertStackBoxToHeapBox(AllocStackInst *asi, SILBasicBlock::iterator next) {+  SILBuilderWithScope builder(asi);+  auto *box =+      builder.createAllocBox(asi->getLoc(), asi->getType().getObjectType());+  auto *projectBox = builder.createProjectBox(asi->getLoc(), box, 0);+  while (!asi->use_empty()) {+    auto *use = *asi->use_begin();++    // Replace all of the alloc_stack's dealloc_stack with a destroy_value of+    // the box.+    if (auto *dsi = dyn_cast<DeallocStackInst>(use->getUser())) {+      SILBuilderWithScope destroyBuilder(dsi);+      destroyBuilder.emitDestroyValueOperation(dsi->getLoc(), box);+      if (next == dsi->getIterator())+        ++next;+      dsi->eraseFromParent();+      continue;+    }++    // Otherwise, make the alloc_stack user now use the project_box.+    use->set(projectBox);+  }++  // Then erase the alloc_stack, incrementing next as we need to.+  if (next == asi->getIterator())+    ++next;+  asi->eraseFromParent();+  return next;+}++//===----------------------------------------------------------------------===//+//                       Per Instruction Implementation+//===----------------------------------------------------------------------===//++namespace {++struct StackSizeLimitState {+  SmallVector<std::pair<AllocRefInst *, BuiltinInst *>, 32> builtinsToProcess;+  bool madeChange = false;+  int stackAllocSize;+  IRGenModule &igm;++  // Max stack promotion that we can perform in a single function.+  StackSizeLimitState(IRGenModule *igm)+      : stackAllocSize(igm->IRGen.Opts.StackPromotionSizeLimit), igm(*igm) {}+};++} // anonymous namespace++static SILBasicBlock::iterator+processAllocStackInst(StackSizeLimitState &state, AllocStackInst *asi,+                      SILBasicBlock::iterator next) {+  // First see if we have already hit our size limit. If we have, just+  // convert to a heap allocation.

In my tests this allows for a 4x speedup on quite a few benchmarks. It's possible that there's some other explanation, but… it seems unlikely. Either way, we should take 4x speedups when we can get them.

gottesmm

comment created time in 11 days

PullRequestReviewEvent

PR closed apple/swift

Bridge flip experiment
+28 -6

7 comments

3 changed files

Catfish-Man

pr closed time in 18 days

pull request commentapple/swift

Bridge flip experiment

Ok pretty good. Looks like hash is the main thing that needs to stay inline

Catfish-Man

comment created time in 18 days

pull request commentapple/swift

Bridge flip experiment

@swift-ci please benchmark

Catfish-Man

comment created time in 18 days

push eventCatfish-Man/swift

David Smith

commit sha 09af015d8c1f3256e19eba5a09fbf1c8bab56a4d

Fix build harder?

view details

push time in 18 days