<commit_before>//===--- Verifier.cpp - Verification of Swift SIL Code --------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#include "swift/SIL/Function.h"
#include "swift/SIL/SILVisitor.h"
#include "swift/AST/Types.h"
#include "swift/AST/Decl.h"
using namespace swift;

namespace {
/// SILVerifier class - This class implements the SIL verifier, which walks over
/// SIL, checking and enforcing its invariants.
class SILVerifier : public SILVisitor<SILVerifier> {
  SILModule &M;
public:
  SILVerifier(SILModule &M) : M(M) {}
  
  void visit(Instruction *I) {
    
    const BasicBlock *BB = I->getParent();
    (void)BB;
    // Check that non-terminators look ok.
    if (!isa<TermInst>(I)) {
      assert(!BB->empty() &&
             "Can't be in a parent block if it is empty");
      assert(&*BB->getInsts().rbegin() != I &&
             "Non-terminators cannot be the last in a block");
    } else {
      assert(&*BB->getInsts().rbegin() == I &&
             "Terminator must be the last in block");
    }

    
    // Dispatch to our more-specialized instances below.
    ((SILVisitor<SILVerifier>*)this)->visit(I);
  }

  void visitAllocInst(AllocInst *AI) {
    assert(AI->getType()->is<LValueType>() &&"Allocation should return lvalue");
  }

  void visitAllocVarInst(AllocVarInst *AI) {
    visitAllocInst(AI);
  }

  void visitApplyInst(ApplyInst *AI) {
    assert(AI->getCallee().getType()->is<FunctionType>() &&
           "Callee of ApplyInst should have function type");
    FunctionType *FT = AI->getCallee().getType()->castTo<FunctionType>();
    assert(AI->getType()->isEqual(FT->getResult()) &&
           "ApplyInst result type mismatch");

    // If there is a single argument to the apply, it might be a scalar or the
    // whole tuple being presented all at once.
    if (AI->getArguments().size() != 1 ||
        !AI->getArguments()[0].getType()->isEqual(FT->getInput())) {
      // Otherwise, we must have a decomposed tuple.  Verify the arguments match
      // up.
      const TupleType *TT = FT->getInput()->castTo<TupleType>();
      (void)TT;
      assert(AI->getArguments().size() == TT->getFields().size() &&
             "ApplyInst contains unexpected argument count for function");
      for (unsigned i = 0, e = AI->getArguments().size(); i != e; ++i)
        assert(AI->getArguments()[i].getType()
                 ->isEqual(TT->getFields()[i].getType()) &&
               "ApplyInst argument type mismatch");
    }
  }

  void visitConstantRefInst(ConstantRefInst *DRI) {
    assert(M.getConstantType(DRI->getConstant())->getCanonicalType() ==<commit_msg>SIL: suppress warning in release builds.<commit_after>//===--- Verifier.cpp - Verification of Swift SIL Code --------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

#include "swift/SIL/Function.h"
#include "swift/SIL/SILVisitor.h"
#include "swift/AST/Types.h"
#include "swift/AST/Decl.h"
using namespace swift;

namespace {
/// SILVerifier class - This class implements the SIL verifier, which walks over
/// SIL, checking and enforcing its invariants.
class SILVerifier : public SILVisitor<SILVerifier> {
  SILModule &M;
public:
  SILVerifier(SILModule &M) : M(M) {}
  
  void visit(Instruction *I) {
    
    const BasicBlock *BB = I->getParent();
    (void)BB;
    // Check that non-terminators look ok.
    if (!isa<TermInst>(I)) {
      assert(!BB->empty() &&
             "Can't be in a parent block if it is empty");
      assert(&*BB->getInsts().rbegin() != I &&
             "Non-terminators cannot be the last in a block");
    } else {
      assert(&*BB->getInsts().rbegin() == I &&
             "Terminator must be the last in block");
    }

    
    // Dispatch to our more-specialized instances below.
    ((SILVisitor<SILVerifier>*)this)->visit(I);
  }

  void visitAllocInst(AllocInst *AI) {
    assert(AI->getType()->is<LValueType>() &&"Allocation should return lvalue");
  }

  void visitAllocVarInst(AllocVarInst *AI) {
    visitAllocInst(AI);
  }

  void visitApplyInst(ApplyInst *AI) {
    assert(AI->getCallee().getType()->is<FunctionType>() &&
           "Callee of ApplyInst should have function type");
    FunctionType *FT = AI->getCallee().getType()->castTo<FunctionType>();
    assert(AI->getType()->isEqual(FT->getResult()) &&
           "ApplyInst result type mismatch");

    // If there is a single argument to the apply, it might be a scalar or the
    // whole tuple being presented all at once.
    if (AI->getArguments().size() != 1 ||
        !AI->getArguments()[0].getType()->isEqual(FT->getInput())) {
      // Otherwise, we must have a decomposed tuple.  Verify the arguments match
      // up.
      const TupleType *TT = FT->getInput()->castTo<TupleType>();
      (void)TT;
      assert(AI->getArguments().size() == TT->getFields().size() &&
             "ApplyInst contains unexpected argument count for function");
      for (unsigned i = 0, e = AI->getArguments().size(); i != e; ++i)
        assert(AI->getArguments()[i].getType()
                 ->isEqual(TT->getFields()[i].getType()) &&
               "ApplyInst argument type mismatch");
    }
  }

  void visitConstantRefInst(ConstantRefInst *DRI) {
    (void)M; // suppress "unused private field" warning for release builds
    assert(M.getConstantType(DRI->getConstant())->getCanonicalType() ==
{'fraction_non_alphanumeric': 0.17855973813420623, 'fraction_numerical': 0.00425531914893617, 'mean_word_length': 2.7013930950938825, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7179970', 'n_tokens_mistral': 1826, 'n_tokens_neox': 1770, 'n_words': 510}